Module: CemAcpt::Actions
- Defined in:
- lib/cem_acpt/actions.rb
Overview
Provides a way to register actions to be executed if the registered actions are included in the list of actions to be executed.
Defined Under Namespace
Classes: Action, ActionConfig, ActionGroup
Class Attribute Summary collapse
-
.config ⇒ Object
readonly
Returns the value of attribute config.
Class Method Summary collapse
-
.configure(world_config) {|CemAcpt::Actions::ActionConfig| ... } ⇒ Object
Configures the Actions module.
-
.execute(**opts) ⇒ Array
Executes the actions in the current action groups.
Class Attribute Details
.config ⇒ Object (readonly)
Returns the value of attribute config.
120 121 122 |
# File 'lib/cem_acpt/actions.rb', line 120 def config @config end |
Class Method Details
.configure(world_config) {|CemAcpt::Actions::ActionConfig| ... } ⇒ Object
Configures the Actions module.
125 126 127 128 129 130 |
# File 'lib/cem_acpt/actions.rb', line 125 def configure(world_config) @config = ActionConfig.new @config.only = world_config.get('actions.only') || [] @config.except = world_config.get('actions.except') || [] yield @config if block_given? end |
.execute(**opts) ⇒ Array
Executes the actions in the current action groups.
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/cem_acpt/actions.rb', line 136 def execute(**opts) context = opts[:context] || {} ordered_groups = config.groups.values.sort_by(&:order) ordered_groups.each_with_object([]) do |group, results| actions = group.filter_actions next if actions.empty? context[:group] = group.name context[:actions] = actions.map(&:name) actions.each do |action| action_opts = opts[action.name.to_sym] || {} results << action.call(context.merge(action_opts)) end end end |