Class: CemAcpt::Actions::ActionGroup
- Inherits:
-
Object
- Object
- CemAcpt::Actions::ActionGroup
- Defined in:
- lib/cem_acpt/actions.rb
Overview
Represents a group of actions.
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#async ⇒ Object
readonly
Returns the value of attribute async.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
Instance Method Summary collapse
- #filter_actions ⇒ Object
-
#initialize(name = :main, **opts) ⇒ ActionGroup
constructor
A new instance of ActionGroup.
-
#register_action(name, order: 0, &block) ⇒ Object
Registers a block to be executed if the registered actions are included in the list of actions to be executed.
- #sort! ⇒ Object
Constructor Details
#initialize(name = :main, **opts) ⇒ ActionGroup
Returns a new instance of ActionGroup.
30 31 32 33 34 35 |
# File 'lib/cem_acpt/actions.rb', line 30 def initialize(name = :main, **opts) @name = name.to_sym @actions = [] @async = opts[:async] || false @order = opts[:order] || 0 end |
Instance Attribute Details
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
28 29 30 |
# File 'lib/cem_acpt/actions.rb', line 28 def actions @actions end |
#async ⇒ Object (readonly)
Returns the value of attribute async.
28 29 30 |
# File 'lib/cem_acpt/actions.rb', line 28 def async @async end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
28 29 30 |
# File 'lib/cem_acpt/actions.rb', line 28 def name @name end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
28 29 30 |
# File 'lib/cem_acpt/actions.rb', line 28 def order @order end |
Instance Method Details
#filter_actions ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/cem_acpt/actions.rb', line 51 def filter_actions filtered = @actions.dup only = CemAcpt::Actions.config.only except = CemAcpt::Actions.config.except filtered.select! { |action| only.include?(action.name) } unless only.empty? filtered.reject! { |action| except.include?(action.name) } unless except.empty? filtered.sort_by!(&:order) filtered end |
#register_action(name, order: 0, &block) ⇒ Object
Registers a block to be executed if the registered actions are included in the list of actions to be executed.
44 45 46 47 48 49 |
# File 'lib/cem_acpt/actions.rb', line 44 def register_action(name, order: 0, &block) new_action = Action.new(name, order, &block) @actions << new_action sort! self # return self to allow chaining end |
#sort! ⇒ Object
61 62 63 |
# File 'lib/cem_acpt/actions.rb', line 61 def sort! @actions.sort_by!(&:order) end |