Sha256: 51b0b35af462274668b93fe205f4ba7a6fa9eaa8f01afa22b7dd536e3df9cf83

Contents?: true

Size: 1.51 KB

Versions: 23

Compression:

Stored size: 1.51 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]))
      end

      protected
        # Get controller filter chain
        #
        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

        # 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

23 entries across 23 versions & 8 rubygems

Version Path
artofmission-rails-footnotes-3.6.0.1 lib/rails-footnotes/notes/filters_note.rb
artofmission-rails-footnotes-3.6.2 lib/rails-footnotes/notes/filters_note.rb
ceritium-rails-footnotes-3.4.1.1 lib/rails-footnotes/notes/filters_note.rb
ceritium-rails-footnotes-3.4.1 lib/rails-footnotes/notes/filters_note.rb
ceritium-rails-footnotes-3.4 lib/rails-footnotes/notes/filters_note.rb
josevalim-rails-footnotes-3.3.1 lib/notes/filters_note.rb
josevalim-rails-footnotes-3.3.2 lib/notes/filters_note.rb
josevalim-rails-footnotes-3.4.1 lib/rails-footnotes/notes/filters_note.rb
josevalim-rails-footnotes-3.4 lib/rails-footnotes/notes/filters_note.rb
josevalim-rails-footnotes-3.5.0 lib/rails-footnotes/notes/filters_note.rb
josevalim-rails-footnotes-3.6.0 lib/rails-footnotes/notes/filters_note.rb
josevalim-rails-footnotes-3.6.1 lib/rails-footnotes/notes/filters_note.rb
josevalim-rails-footnotes-3.6.2 lib/rails-footnotes/notes/filters_note.rb
lexrupy-rails-footnotes-3.3.2 lib/rails-footnotes/notes/filters_note.rb
lexrupy-rails-footnotes-3.4.1 lib/rails-footnotes/notes/filters_note.rb
lexrupy-rails-footnotes-3.4 lib/rails-footnotes/notes/filters_note.rb
omghax-rails-footnotes-3.6.1 lib/rails-footnotes/notes/filters_note.rb
omghax-rails-footnotes-3.6.2 lib/rails-footnotes/notes/filters_note.rb
rails-footnotes-3.6.5 lib/rails-footnotes/notes/filters_note.rb
rails-footnotes-3.6.4 lib/rails-footnotes/notes/filters_note.rb