Class: Cuprum::Rails::Controllers::Action Private
- Inherits:
-
Object
- Object
- Cuprum::Rails::Controllers::Action
- Extended by:
- Forwardable
- Defined in:
- lib/cuprum/rails/controllers/action.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
This class should not be initialized directly. Instead, use the Cuprum::Rails::Controller.action class method to define an action.
Implements a controller action.
Instance Attribute Summary collapse
-
#action_class ⇒ Class
readonly
private
The class of the action command.
-
#action_name ⇒ String, Symbol
readonly
private
The name of the action.
Instance Method Summary collapse
-
#call(controller, request) ⇒ #call
private
Executes the controller action.
-
#initialize(action_class:, action_name:, member_action: false) ⇒ Action
constructor
private
A new instance of Action.
-
#member_action? ⇒ Boolean
private
True if the action acts on a collection item, not on the collection as a whole.
Constructor Details
#initialize(action_class:, action_name:, member_action: false) ⇒ Action
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Action.
24 25 26 27 28 29 30 31 32 |
# File 'lib/cuprum/rails/controllers/action.rb', line 24 def initialize( action_class:, action_name:, member_action: false ) @action_class = action_class @action_name = action_name @member_action = !!member_action end |
Instance Attribute Details
#action_class ⇒ Class (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the class of the action command.
35 36 37 |
# File 'lib/cuprum/rails/controllers/action.rb', line 35 def action_class @action_class end |
#action_name ⇒ String, Symbol (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the name of the action.
38 39 40 |
# File 'lib/cuprum/rails/controllers/action.rb', line 38 def action_name @action_name end |
Instance Method Details
#call(controller, request) ⇒ #call
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Executes the controller action.
-
Initializes the action command with the resource.
-
Calls the command with the request.
-
Builds the responder with the resource and action metadata.
-
Calls the responder with the action result.
52 53 54 55 56 57 58 |
# File 'lib/cuprum/rails/controllers/action.rb', line 52 def call(controller, request) responder = build_responder(controller, request) action = apply_middleware(controller, action_class.new) result = action.call(request: request, **controller.) responder.call(result) end |
#member_action? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns true if the action acts on a collection item, not on the collection as a whole.
62 63 64 |
# File 'lib/cuprum/rails/controllers/action.rb', line 62 def member_action? @member_action end |