Class: Cuprum::Rails::Responders::BaseResponder
- Inherits:
-
Object
- Object
- Cuprum::Rails::Responders::BaseResponder
- Extended by:
- Forwardable
- Defined in:
- lib/cuprum/rails/responders/base_responder.rb
Overview
Abstract base class for defining responders.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#action_name ⇒ String, Symbol
readonly
The name of the action to match.
-
#controller ⇒ Cuprum::Rails::Controller
readonly
The called controller.
-
#controller_name ⇒ String
readonly
The name of the called controller.
-
#request ⇒ Cuprum::Rails::Request
readonly
The request to the controller.
-
#resource ⇒ Cuprum::Rails::Resource
readonly
The resource for the controller.
-
#result ⇒ Cuprum::Result
readonly
The result of calling the action.
Instance Method Summary collapse
-
#call(result) ⇒ #call
Generates the response object for the result.
-
#initialize(action_name:, controller:, request:, member_action: false, **_options) ⇒ BaseResponder
constructor
A new instance of BaseResponder.
-
#member_action? ⇒ true, false
True if the action is a member action, otherwise false.
-
#routes ⇒ Cuprum::Rails::Routes
Helper for accessing the configured routes for the resource.
Constructor Details
#initialize(action_name:, controller:, request:, member_action: false, **_options) ⇒ BaseResponder
Returns a new instance of BaseResponder.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/cuprum/rails/responders/base_responder.rb', line 15 def initialize( action_name:, controller:, request:, member_action: false, ** ) @action_name = action_name @controller = controller @controller_name = controller.class.name @member_action = !!member_action # rubocop:disable Style/DoubleNegation @request = request @resource = controller.class.resource end |
Instance Attribute Details
#action_name ⇒ String, Symbol (readonly)
Returns the name of the action to match.
31 32 33 |
# File 'lib/cuprum/rails/responders/base_responder.rb', line 31 def action_name @action_name end |
#controller ⇒ Cuprum::Rails::Controller (readonly)
Returns the called controller.
34 35 36 |
# File 'lib/cuprum/rails/responders/base_responder.rb', line 34 def controller @controller end |
#controller_name ⇒ String (readonly)
Returns the name of the called controller.
37 38 39 |
# File 'lib/cuprum/rails/responders/base_responder.rb', line 37 def controller_name @controller_name end |
#request ⇒ Cuprum::Rails::Request (readonly)
Returns the request to the controller.
40 41 42 |
# File 'lib/cuprum/rails/responders/base_responder.rb', line 40 def request @request end |
#resource ⇒ Cuprum::Rails::Resource (readonly)
Returns the resource for the controller.
43 44 45 |
# File 'lib/cuprum/rails/responders/base_responder.rb', line 43 def resource @resource end |
#result ⇒ Cuprum::Result (readonly)
Returns the result of calling the action.
46 47 48 |
# File 'lib/cuprum/rails/responders/base_responder.rb', line 46 def result @result end |
Instance Method Details
#call(result) ⇒ #call
Generates the response object for the result.
53 54 55 |
# File 'lib/cuprum/rails/responders/base_responder.rb', line 53 def call(result) @result = result end |
#member_action? ⇒ true, false
Returns true if the action is a member action, otherwise false.
59 60 61 |
# File 'lib/cuprum/rails/responders/base_responder.rb', line 59 def member_action? @member_action end |
#routes ⇒ Cuprum::Rails::Routes
Helper for accessing the configured routes for the resource.
Any wildcards from the path params will be applied to the routes.
68 69 70 |
# File 'lib/cuprum/rails/responders/base_responder.rb', line 68 def routes resource.routes.with_wildcards(routes_wildcards) end |