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.



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

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

Instance Attribute Details

#exceptObject

Returns the value of attribute except.



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

def except
  @except
end

#groupsObject (readonly)

Returns the value of attribute groups.



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

def groups
  @groups
end

#onlyObject

Returns the value of attribute only.



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

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



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

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



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

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.



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

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

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