Class | Footnotes::Notes::FiltersNote |
In: |
lib/rails-footnotes/notes/filters_note.rb
|
Parent: | AbstractNote |
# File lib/rails-footnotes/notes/filters_note.rb, line 6 def initialize(controller) @controller = controller @parsed_filters = parse_filters end
# File lib/rails-footnotes/notes/filters_note.rb, line 15 def content mount_table(@parsed_filters.unshift([:name, :type, :actions])) end
# File lib/rails-footnotes/notes/filters_note.rb, line 11 def legend "Filter chain for #{@controller.class.to_s}" end
This receives a filter, creates a mock controller and check in which actions the filter is performed
# File lib/rails-footnotes/notes/filters_note.rb, line 31 def controller_filtered_actions(filter) mock_controller = Footnotes::Extensions::MockController.new return @controller.class.action_methods.select { |action| mock_controller.action_name = action #remove conditions (this would call a Proc on the mock_controller) filter.options.merge!(:if => nil, :unless => nil) filter.__send__(:should_run_callback?, mock_controller) }.map(&:to_sym) end
Get controller filter chain
# File lib/rails-footnotes/notes/filters_note.rb, line 22 def parse_filters return @controller.class.filter_chain.collect do |filter| [parse_method(filter.method), filter.type.inspect, controller_filtered_actions(filter).inspect] end end