Class: Cuprum::Rails::Controllers::Action Private

Inherits:
Object
  • Object
show all
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.

Note:

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

Instance Method Summary collapse

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.

Parameters:

  • action_class (Class)

    the class of the action command. Must be constructible with keyword :resource.

  • action_name (String, Symbol)

    the name of the action.

  • member_action (Boolean) (defaults to: false)

    true if the action acts on a collection item, not on the collection as a whole.



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_classClass (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.

Returns:

  • (Class)

    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_nameString, 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.

Returns:

  • (String, Symbol)

    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.

  1. Initializes the action command with the resource.

  2. Calls the command with the request.

  3. Builds the responder with the resource and action metadata.

  4. Calls the responder with the action result.

Parameters:

Returns:

  • (#call)

    the response object.



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.action_options)

  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.

Returns:

  • (Boolean)

    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