Sha256: 31179cc98a347215e538773435a86fbc87f0ede55c1694cbdb82412374e968f8

Contents?: true

Size: 1.57 KB

Versions: 9

Compression:

Stored size: 1.57 KB

Contents

require "#{File.dirname(__FILE__)}/abstract_note"

module Footnotes
  module Notes
    class FiltersNote < AbstractNote
      def initialize(controller)
        @controller = controller
        @parsed_filters = parse_filters
      end

      def legend
        "Filter chain for #{@controller.class.to_s}"
      end

      def content
        mount_table(@parsed_filters.unshift([:name, :type, :actions]), :summary => "Debug information for #{title}")
      end

      protected
        # Get controller filter chain
        #
        def parse_filters
          return [] # TODO @controller.class.filter_chain.collect do |filter|
#            [parse_method(filter.method), filter.type.inspect, controller_filtered_actions(filter).inspect]
#          end
        end

        # This receives a filter, creates a mock controller and check in which
        # actions the filter is performed
        #
        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
        
        def parse_method(method = '')
          escape(method.inspect.gsub(RAILS_ROOT, ''))
        end
    end
  end

  module Extensions
    class MockController < Struct.new(:action_name); end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
rails-footnotes-3.7.2 lib/rails-footnotes/notes/filters_note.rb
rails-footnotes-3.7.1 lib/rails-footnotes/notes/filters_note.rb
rails-footnotes-3.7.1.pre lib/rails-footnotes/notes/filters_note.rb
rails3-footnotes-4.0.0.pre.4 lib/rails-footnotes/notes/filters_note.rb
rails3-footnotes-4.0.0.pre.3 lib/rails-footnotes/notes/filters_note.rb
rails-footnotes-3.7.0 lib/rails-footnotes/notes/filters_note.rb
rails3-footnotes-4.0.0.pre.2 lib/rails-footnotes/notes/filters_note.rb
rails3-footnotes-4.0.0.pre.1 lib/rails-footnotes/notes/filters_note.rb
rails3-footnotes-4.0.0.pre lib/rails-footnotes/notes/filters_note.rb