Module: Cuprum::Rails::Controllers::ClassMethods::Actions
- Defined in:
- lib/cuprum/rails/controllers/class_methods/actions.rb
Overview
Provides a DSL for defining controller actions.
Instance Method Summary collapse
-
#action(action_name, action_class, member: false) ⇒ Object
Defines a controller action.
-
#actions ⇒ Hash<Symbol, Cuprum::Rails::Controllers::Action>
The actions defined for the controller.
- #apply_request_defaults(request) ⇒ Object
-
#build_request(context, **options) ⇒ Cuprum::Rails::Request
Generates a Cuprum::Rails::Request from a native request.
- #own_actions ⇒ Object
Instance Method Details
#action(action_name, action_class, member: false) ⇒ Object
Defines a controller action.
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/cuprum/rails/controllers/class_methods/actions.rb', line 16 def action(action_name, action_class, member: false) validate_name(action_name, as: 'action name') validate_class(action_class, as: 'action class') action_name = action_name.intern own_actions[action_name] = Cuprum::Rails::Controllers::Action.new( action_class: action_class, action_name: action_name, member_action: member ) define_action(action_name) end |
#actions ⇒ Hash<Symbol, Cuprum::Rails::Controllers::Action>
Returns the actions defined for the controller.
32 33 34 35 36 37 38 |
# File 'lib/cuprum/rails/controllers/class_methods/actions.rb', line 32 def actions ancestors .select { |ancestor| ancestor.respond_to?(:own_actions) } .reverse_each .map(&:own_actions) .reduce(&:merge) end |
#apply_request_defaults(request) ⇒ Object
41 42 43 |
# File 'lib/cuprum/rails/controllers/class_methods/actions.rb', line 41 def apply_request_defaults(request) request.format ||= configuration.default_format end |
#build_request(context, **options) ⇒ Cuprum::Rails::Request
Generates a Cuprum::Rails::Request from a native request.
Override this method to generate a request subclass.
53 54 55 56 57 58 59 |
# File 'lib/cuprum/rails/controllers/class_methods/actions.rb', line 53 def build_request(context, **) Cuprum::Rails::Request.build( context: context, request: context.request, ** ) end |
#own_actions ⇒ Object
62 63 64 65 66 |
# File 'lib/cuprum/rails/controllers/class_methods/actions.rb', line 62 def own_actions # :nocov: @own_actions ||= {} # :nocov: end |