Class: FilterDecrufter::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/filter_decrufter/checker.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeReport

Returns a new instance of Report.



38
39
40
# File 'lib/filter_decrufter/checker.rb', line 38

def initialize
 @hits = []
end

Instance Attribute Details

#hitsObject

Returns the value of attribute hits.



32
33
34
# File 'lib/filter_decrufter/checker.rb', line 32

def hits
  @hits
end

Class Method Details

.instanceObject



34
35
36
# File 'lib/filter_decrufter/checker.rb', line 34

def self.instance
  @instance ||= Report.new
end

Instance Method Details

#add(hit) ⇒ Object



42
43
44
45
# File 'lib/filter_decrufter/checker.rb', line 42

def add(hit)
  raise "Oops filter_decrufter can't handle this version of Rails" unless hit.controller_class.respond_to?(:action_methods)
  hits << hit
end

#check_constraint(name, hit) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/filter_decrufter/checker.rb', line 57

def check_constraint(name, hit)
  [hit.populated_only_except_options[name]].flatten.each do |action_syms|
    [action_syms].flatten.each do |action_name|
      if !hit.actions_include?(action_name)
        puts "#{hit.controller_class} #{hit.filter_type} '#{hit.filter_name}' has an :#{name} constraint with a non-existent action name '#{action_name}'"
      end
    end
  end
end

#find_problemsObject



47
48
49
50
51
52
53
54
55
# File 'lib/filter_decrufter/checker.rb', line 47

def find_problems
  hits.each do |hit|
    hit.populated_only_except_options.each do |k,v|
      [:only, :except].each do |constraint_name|
        check_constraint(constraint_name, hit) if hit.populated_only_except_options[constraint_name].present?
      end
    end
  end
end