Module: Upgrow::Actions

Extended by:
Actions
Included in:
Actions
Defined in:
lib/upgrow/actions.rb

Overview

This module offers helpers to work with the collection of Actions loaded in the application.

Actions are created with a concrete, predefined interface. This allows them to be uniformly instantiated in the context of an application, which is helpful to prevent duplications.

Instance Method Summary collapse

Instance Method Details

#[](*names) ⇒ Action

Convenience method to retrieve an Action based on a key name optionally namespaced.

Examples:

Retrieve Action based on a global key name

Actions['show'] #=> ShowAction

Retrieve a namespaced Action

Actions['articles', 'show'] #=> Articles::ShowAction

Parameters:

  • names (Array<String>)

    one or more names, the last one being the name of the Action without the “Action” suffix, optionally lowercased.

Returns:

  • (Action)

    the Action specified by the names.



26
27
28
29
# File 'lib/upgrow/actions.rb', line 26

def [](*names)
  action_class_name = "#{names.map(&:capitalize).join("::")}Action"
  Object.const_get(action_class_name)
end