class SnipSnip::Reporter
Handles outputting unnecessarily selected columns to the logs.
Constants
- Result
Represents a result that has unused columns.
Attributes
results[R]
Public Class Methods
new()
click to toggle source
# File lib/snip_snip/reporter.rb, line 15 def initialize @results = find_results end
report(controller)
click to toggle source
Report on the specified controller.
# File lib/snip_snip/reporter.rb, line 35 def self.report(controller) new.report(controller) end
Public Instance Methods
report(controller)
click to toggle source
Report on the unused columns that were selected during the course of the processing the action on the given controller.
# File lib/snip_snip/reporter.rb, line 21 def report(controller) return if results.empty? action_display = "#{controller.controller_name}##{controller.action_name}" SnipSnip.logger.info(action_display) results.sort_by(&:report).each do |result| SnipSnip.logger.info(" #{result.report}") end ensure Registry.clear end
Private Instance Methods
find_results()
click to toggle source
# File lib/snip_snip/reporter.rb, line 41 def find_results Registry.each_record.each_with_object([]) do |record, records| accessed = record.accessed_fields unused = (record.attributes.keys - accessed) records << result_from(record, unused) if unused.any? end end
result_from(record, unused)
click to toggle source
# File lib/snip_snip/reporter.rb, line 49 def result_from(record, unused) primary_key = record.class.primary_key Result.new(record.class.name, record.public_send(primary_key), unused) end