Class: Domainic::Command::Context::AttributeSet
- Inherits:
-
Object
- Object
- Domainic::Command::Context::AttributeSet
- Defined in:
- lib/domainic/command/context/attribute_set.rb
Overview
A collection class for managing a set of command context attributes. This class provides a simple interface for storing, accessing, and iterating over Attribute instances.
Instance Method Summary collapse
-
#[](attribute_name) ⇒ Attribute?
Retrieves an attribute by name.
-
#add(attribute) ⇒ void
Adds an attribute to the set.
-
#all ⇒ Array<Attribute>
Returns all attributes in the set.
-
#each {|Attribute| ... } ⇒ void
Iterates over each attribute in the set.
-
#each_with_object(object) {|Attribute, Object| ... } ⇒ Object
Iterates over each attribute in the set with an object.
-
#initialize ⇒ AttributeSet
constructor
Creates a new AttributeSet instance.
Constructor Details
#initialize ⇒ AttributeSet
Creates a new AttributeSet instance
23 24 25 |
# File 'lib/domainic/command/context/attribute_set.rb', line 23 def initialize @lookup = {} end |
Instance Method Details
#[](attribute_name) ⇒ Attribute?
Retrieves an attribute by name
33 34 35 |
# File 'lib/domainic/command/context/attribute_set.rb', line 33 def [](attribute_name) @lookup[attribute_name.to_sym] end |
#add(attribute) ⇒ void
This method returns an undefined value.
Adds an attribute to the set
44 45 46 47 48 49 50 |
# File 'lib/domainic/command/context/attribute_set.rb', line 44 def add(attribute) unless attribute.is_a?(Attribute) raise ArgumentError, 'Attribute must be an instance of Domainic::Command::Context::Attribute' end @lookup[attribute.name] = attribute end |
#all ⇒ Array<Attribute>
Returns all attributes in the set
56 57 58 |
# File 'lib/domainic/command/context/attribute_set.rb', line 56 def all @lookup.values end |
#each {|Attribute| ... } ⇒ void
This method returns an undefined value.
Iterates over each attribute in the set
66 67 68 |
# File 'lib/domainic/command/context/attribute_set.rb', line 66 def each(...) all.each(...) end |
#each_with_object(object) {|Attribute, Object| ... } ⇒ Object
Iterates over each attribute in the set with an object
78 79 80 |
# File 'lib/domainic/command/context/attribute_set.rb', line 78 def each_with_object(...) all.each_with_object(...) # steep:ignore UnresolvedOverloading end |