module Automux::Controller::Support::Filters

Attributes

filters[R]

Public Instance Methods

after_inherited(base) click to toggle source

This is a custom hook intended to run after the subclass definition is read. This helps in calling the before_filter at the top but defining its logic later. See: automux/initializers/custom_hooks.rb for invocation.

# File lib/automux/controller/support/filters.rb, line 23
def after_inherited(base)
  # E.g. filters = { automate: [:load_recipe, :load_session], edit: [:load_recipe] }
  base.class_eval do
    #                    |automate, [:load_recipe, :load_session]|
    filters.each_pair do |name, filter_list|

      # def automate_with_filters
      #   load_recipe
      #   load_session
      #   automate_without_filters
      # end
      define_method "#{ name }_with_filters" do
        filter_list.each { |filter_name| send(filter_name) }
        send("#{ name }_without_filters")
      end

      # alias_method_chain automate, filters
      alias_method "#{ name }_without_filters", name
      alias_method name, "#{ name }_with_filters"
    end
  end
end
before_filter(filter_name, options) click to toggle source

before_filter does not define its logic right away.

# File lib/automux/controller/support/filters.rb, line 14
def before_filter(filter_name, options)
  [options[:only]].flatten.each do |action|
    add_filter(filter_name, action)
  end
end
inherited(base) click to toggle source

Filters is included in the Base controller and all the following methods are intended for its subclasses.

# File lib/automux/controller/support/filters.rb, line 9
def inherited(base)
  base.instance_variable_set '@filters', {}
end