Class: Servactory::Actions::Collection
- Inherits:
-
Object
- Object
- Servactory::Actions::Collection
- Extended by:
- Forwardable
- Defined in:
- lib/servactory/actions/collection.rb
Overview
Mutable collection manager for Action objects.
## Purpose
Stores Action objects and provides query methods to retrieve actions sorted by position. Wraps a Set for unique action storage with position-based ordering capabilities.
## Usage
“‘ruby actions = Servactory::Actions::Collection.new actions << Action.new(:first, position: 1) actions << Action.new(:second, position: 2)
actions.sorted_by_position # => Collection with sorted actions actions.empty? # => false actions.size # => 2 “‘
## Integration
Used by Servactory::Actions::Stages::Stage to store actions within a stage, and by Servactory::Actions::Tools::Runner to execute actions in the correct order.
Instance Method Summary collapse
-
#<<(action) ⇒ Set
Adds an action to the collection.
-
#each {|Action| ... } ⇒ Object
Iterates over all actions in the collection.
-
#empty? ⇒ Boolean
Checks if the collection is empty.
-
#initialize(collection = Set.new) ⇒ Collection
constructor
Creates a new actions collection.
-
#size ⇒ Integer
Returns the number of actions in the collection.
-
#sort_by {|Action| ... } ⇒ Array<Action>
Sorts actions by the given block.
-
#sorted_by_position ⇒ Collection
Returns a new collection with actions sorted by position.
-
#to_h ⇒ Hash
Converts collection to a hash.
Constructor Details
#initialize(collection = Set.new) ⇒ Collection
Creates a new actions collection.
58 59 60 |
# File 'lib/servactory/actions/collection.rb', line 58 def initialize(collection = Set.new) @collection = collection end |
Instance Method Details
#<<(action) ⇒ Set
Adds an action to the collection.
53 |
# File 'lib/servactory/actions/collection.rb', line 53 def_delegators :@collection, :<<, :each, :to_h, :sort_by, :size, :empty? |
#each {|Action| ... } ⇒ Object
Iterates over all actions in the collection.
53 |
# File 'lib/servactory/actions/collection.rb', line 53 def_delegators :@collection, :<<, :each, :to_h, :sort_by, :size, :empty? |
#empty? ⇒ Boolean
Checks if the collection is empty.
53 |
# File 'lib/servactory/actions/collection.rb', line 53 def_delegators :@collection, :<<, :each, :to_h, :sort_by, :size, :empty? |
#size ⇒ Integer
Returns the number of actions in the collection.
53 |
# File 'lib/servactory/actions/collection.rb', line 53 def_delegators :@collection, :<<, :each, :to_h, :sort_by, :size, :empty? |
#sort_by {|Action| ... } ⇒ Array<Action>
Sorts actions by the given block.
53 |
# File 'lib/servactory/actions/collection.rb', line 53 def_delegators :@collection, :<<, :each, :to_h, :sort_by, :size, :empty? |
#sorted_by_position ⇒ Collection
Returns a new collection with actions sorted by position.
69 70 71 |
# File 'lib/servactory/actions/collection.rb', line 69 def sorted_by_position Collection.new(sort_by(&:position)) end |
#to_h ⇒ Hash
Converts collection to a hash.
53 |
# File 'lib/servactory/actions/collection.rb', line 53 def_delegators :@collection, :<<, :each, :to_h, :sort_by, :size, :empty? |