Module: Automux::Controller::Support::Filters
- Included in:
- Base
- Defined in:
- lib/automux/controller/support/filters.rb
Instance Method Summary collapse
-
#after_inherited(base) ⇒ Object
This is a custom hook intended to run after the subclass definition is read.
-
#before_filter(filter_name, options) ⇒ Object
before_filter does not define its logic right away.
-
#inherited(base) ⇒ Object
Filters is included in the Base controller and all the following methods are intended for its subclasses.
Instance Method Details
#after_inherited(base) ⇒ Object
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.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# 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) ⇒ Object
before_filter does not define its logic right away.
14 15 16 17 18 |
# File 'lib/automux/controller/support/filters.rb', line 14 def before_filter(filter_name, ) [[:only]].flatten.each do |action| add_filter(filter_name, action) end end |
#inherited(base) ⇒ Object
Filters is included in the Base controller and all the following methods are intended for its subclasses.
9 10 11 |
# File 'lib/automux/controller/support/filters.rb', line 9 def inherited(base) base.instance_variable_set '@filters', {} end |