Skip to content

Commit

Permalink
Output log when fail to find the target file
Browse files Browse the repository at this point in the history
  • Loading branch information
makicamel committed Oct 9, 2023
1 parent 4477c8c commit 02fd6d5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 0 additions & 1 deletion lib/bulletmark_repairer/associations_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
module BulletmarkRepairer
class AssociationsBuilder
def build(marker)
# TODO: Notify if fail to find suitable file to be patched
return if marker.skip?

if associations[marker.index]
Expand Down
3 changes: 2 additions & 1 deletion lib/bulletmark_repairer/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

module BulletmarkRepairer
class Configration
attr_accessor :skip_file_list
attr_accessor :skip_file_list, :logger
attr_writer :development

def initialize
@development = false
@skip_file_list = []
@logger = Logger.new("#{Rails.root}/log/bulletmark_repairer.log")
end

def development?
Expand Down
15 changes: 15 additions & 0 deletions lib/bulletmark_repairer/markers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def add_association(notification)
end

def skip?
log_patchable_files_not_be_found
index.nil? || file_name.remove("#{Rails.root}/").in?(BulletmarkRepairer.config.skip_file_list)
end

Expand All @@ -53,6 +54,20 @@ def n_plus_one_in_view?

private

def log_patchable_files_not_be_found
return if index

BulletmarkRepairer.config.logger.info <<~LOG
Repairer couldn't patch
#{"#{@controller}_controller".camelize.constantize}##{@action}
#{base_class} => #{associations}
Might be able to add one of the following
includes(#{associations}) / includes(#{base_class.underscore}: #{associations}) / includes(#{base_class.underscore.pluralize}: #{associations})
Stacktraces
#{@stacktraces.join("\n ")}
LOG
end

def set_up
@n_plus_one_in_view = @stacktraces.any? { |stacktrace| stacktrace.match?(%r{\A#{Rails.root}/app/views/[./\w]+:\d+:in `[\w]+'\z}) }

Expand Down

0 comments on commit 02fd6d5

Please sign in to comment.