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.
31 32 33 34 35 36 |
# File 'lib/cem_acpt/actions.rb', line 31 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.
29 30 31 |
# File 'lib/cem_acpt/actions.rb', line 29 def actions @actions end |
#async ⇒ Object (readonly)
Returns the value of attribute async.
29 30 31 |
# File 'lib/cem_acpt/actions.rb', line 29 def async @async end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
29 30 31 |
# File 'lib/cem_acpt/actions.rb', line 29 def name @name end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
29 30 31 |
# File 'lib/cem_acpt/actions.rb', line 29 def order @order end |
Instance Method Details
#filter_actions ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/cem_acpt/actions.rb', line 52 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.
45 46 47 48 49 50 |
# File 'lib/cem_acpt/actions.rb', line 45 def register_action(name, order: 0, &block) new_action = Action.new(name, order: order, &block) @actions << new_action sort! self # return self to allow chaining end |
#sort! ⇒ Object
62 63 64 |
# File 'lib/cem_acpt/actions.rb', line 62 def sort! @actions.sort_by!(&:order) end |