Module: ResourcesController::IncludeActions
- Defined in:
- lib/resources_controller/include_actions.rb
Overview
extension for any module that is used as an Actions module.
After extending the module (say ‘MyActions’), instead of doing this:
self.include ActionsModule
do this:
ActionsModule.include_actions(self, <:only or :except options>)
RC extends any actions module with this automatically, so you don’t need to know about it.
However, if you ahve any special behaviour in your actions module that is sensitive to :only and :except, you can define your own include_actions method on that module to effect this special behaviour.
Instance Method Summary collapse
- #action_methods_to_remove(options = {}) ⇒ Object
- #include_actions(controller, options = {}) ⇒ Object
- #remove_action_method(action) ⇒ Object
Instance Method Details
#action_methods_to_remove(options = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/resources_controller/include_actions.rb', line 27 def action_methods_to_remove( = {}) if [:only] instance_methods - Array([:only]).map(&:to_s) elsif [:except] Array([:except]).map(&:to_s) & instance_methods else [] end end |
#include_actions(controller, options = {}) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/resources_controller/include_actions.rb', line 15 def include_actions(controller, = {}) .assert_valid_keys(:only, :except) raise ArgumentError, "you can only specify either :except or :only, not both" if [:only] && [:except] mixin = self.clone action_methods_to_remove().each {|a| mixin.remove_action_method(a) } controller.send :include, mixin end |
#remove_action_method(action) ⇒ Object
23 24 25 |
# File 'lib/resources_controller/include_actions.rb', line 23 def remove_action_method(action) undef_method action end |