Sha256: 5d5cdafbc70373526e7bf5f3175cc6ece6f734b0461d27110f5ae1268b8fcda0

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module Upgrow
  # 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.
  module Actions
    extend self

    # 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.
    def [](*names)
      action_class_name = "#{names.map(&:capitalize).join("::")}Action"
      Object.const_get(action_class_name)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
upgrow-0.0.5 lib/upgrow/actions.rb
upgrow-0.0.4 lib/upgrow/actions.rb