module Upgrow::Actions

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.

Public Instance Methods

[](*names) click to toggle source

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

@example Retrieve Action based on a global key name

Actions['show'] #=> ShowAction

@example Retrieve a namespaced Action

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

@param names [Array<String>] one or more names, the last one being the

name of the Action without the "Action" suffix, optionally lowercased.

@return [Action] the Action specified by the names.

# File lib/upgrow/actions.rb, line 26
def [](*names)
  action_class_name = "#{names.map(&:capitalize).join("::")}Action"
  Object.const_get(action_class_name)
end