Class: CemAcpt::Actions::ActionConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/cem_acpt/actions.rb

Overview

Represents the configuration for the Actions module.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeActionConfig

Returns a new instance of ActionConfig.



71
72
73
74
75
76
77
# File 'lib/cem_acpt/actions.rb', line 71

def initialize
  @groups = {
    main: ActionGroup.new,
  }
  @only = []
  @except = []
end

Instance Attribute Details

#exceptObject

Returns the value of attribute except.



69
70
71
# File 'lib/cem_acpt/actions.rb', line 69

def except
  @except
end

#groupsObject (readonly)

Returns the value of attribute groups.



69
70
71
# File 'lib/cem_acpt/actions.rb', line 69

def groups
  @groups
end

#onlyObject

Returns the value of attribute only.



69
70
71
# File 'lib/cem_acpt/actions.rb', line 69

def only
  @only
end

Instance Method Details

#[](key) ⇒ Object

Returns the action group with the specified name.

Parameters:

  • key (String, Symbol)

    the name of the action group



81
82
83
# File 'lib/cem_acpt/actions.rb', line 81

def [](key)
  groups[key.to_sym]
end

#action_names(include_all: false) ⇒ Array<String>

Returns a list of the names of all registered actions.

Returns:

  • (Array<String>)

    the list of all registered action names



101
102
103
104
105
# File 'lib/cem_acpt/actions.rb', line 101

def action_names(include_all: false)
  return groups.values.map { |a| a.actions }.flatten.map(&:name).uniq if include_all

  groups.values.map { |a| a.filter_actions }.flatten.map(&:name).uniq
end

#register_group(name, **opts) ⇒ Object

Registers an action group. Actions groups are logical groups of actions that can be executed in parallel.

Parameters:

  • name (String, Symbol)

    the name of the action group

  • async (Boolean)

    whether the actions in the group should be executed in parallel. Defaults to false.

  • order (Integer)

    the order in which the action group should be executed. Lower numbers are executed first.



92
93
94
95
96
97
# File 'lib/cem_acpt/actions.rb', line 92

def register_group(name, **opts)
  return groups[name] if groups.key?(name)

  groups[name] = ActionGroup.new(name, **opts)
  groups[name]
end