Class Footnotes::Notes::FiltersNote
In: lib/rails-footnotes/notes/filters_note.rb
Parent: AbstractNote

Methods

Public Class methods

[Source]

# File lib/rails-footnotes/notes/filters_note.rb, line 6
      def initialize(controller)
        @controller = controller
        @parsed_filters = parse_filters
      end

Public Instance methods

[Source]

# File lib/rails-footnotes/notes/filters_note.rb, line 15
      def content
        mount_table(@parsed_filters.unshift([:name, :type, :actions]))
      end

[Source]

# File lib/rails-footnotes/notes/filters_note.rb, line 11
      def legend
        "Filter chain for #{@controller.class.to_s}"
      end

Protected Instance methods

This receives a filter, creates a mock controller and check in which actions the filter is performed

[Source]

# 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

[Source]

# 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

[Source]

# File lib/rails-footnotes/notes/filters_note.rb, line 44
        def parse_method(method = '')
          escape(method.inspect.gsub(RAILS_ROOT, ''))
        end

[Validate]