Module: Mithril::Controllers::Mixins::ActionsBase
- Extended by:
- MixinWithActions
- Defined in:
- lib/mithril/controllers/mixins/actions_base.rb
Overview
Core functions for implementing a command+args response model. ActionsBase should be mixed in to controllers, either directly or via an intermediate Mixin that implements default or shared actions.
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
- #request ⇒ Mithril::Request readonly
Instance Method Summary collapse
-
#actions(allow_private = false) ⇒ Hash
Lists the actions available to the current controller.
-
#has_action?(key, allow_private = false) ⇒ Boolean
True if the action is available on this controller with the specified private setting; false otherwise.
-
#invoke_action(command, arguments, allow_private = false) ⇒ String?
Searches for a matching action.
Methods included from Mixin
Instance Attribute Details
#request ⇒ Mithril::Request (readonly)
66 67 68 |
# File 'lib/mithril/controllers/mixins/actions_base.rb', line 66 def request @request end |
Instance Method Details
#actions(allow_private = false) ⇒ Hash
Lists the actions available to the current controller.
72 73 74 75 76 77 78 79 80 |
# File 'lib/mithril/controllers/mixins/actions_base.rb', line 72 def actions(allow_private = false) actions = {} actions.update(self.class.superclass.actions(allow_private)) if (klass = self.class.superclass).respond_to? :actions actions.update(self.class.actions(allow_private)) actions end |
#has_action?(key, allow_private = false) ⇒ Boolean
Returns True if the action is available on this controller with the specified private setting; false otherwise.
86 87 88 89 90 |
# File 'lib/mithril/controllers/mixins/actions_base.rb', line 86 def has_action?(key, allow_private = false) return false if key.nil? self.actions(allow_private).has_key? key.intern end |
#invoke_action(command, arguments, allow_private = false) ⇒ String?
Searches for a matching action. If found, calls the action with the given session hash and arguments list.
105 106 107 108 109 110 111 112 |
# File 'lib/mithril/controllers/mixins/actions_base.rb', line 105 def invoke_action(command, arguments, allow_private = false) session = request ? request.session || {} : {} if self.has_action? command, allow_private self.send :"action_#{command}", session, arguments else nil end # if-else end |