Class: Treaty::Entity::Attribute::Collection
- Inherits:
-
Object
- Object
- Treaty::Entity::Attribute::Collection
- Extended by:
- Forwardable
- Defined in:
- lib/treaty/entity/attribute/collection.rb
Overview
Collection wrapper for sets of attributes.
Purpose
Provides a unified interface for working with collections of attributes. Uses Ruby Set internally for uniqueness but exposes Array-like interface.
Usage
Used internally by:
- Request/Response factories (to store attributes)
- Attribute::Base (to store nested attributes)
Methods
Delegates common collection methods to internal Set:
<<- Add attributeeach,map,select,reject- Iterationfind,first- Accesssize,empty?- Size checksto_h- Convert to hash
Custom methods:
exists?- Returns true if collection is not empty
Example
collection = Collection.new
collection << Attribute::Base.new(:name, :string)
collection << Attribute::Base.new(:age, :integer)
collection.size # => 2
collection.exists? # => true
Instance Method Summary collapse
-
#exists? ⇒ Boolean
Checks if collection has any elements.
-
#initialize(collection = Set.new) ⇒ Collection
constructor
Creates a new collection instance.
Constructor Details
#initialize(collection = Set.new) ⇒ Collection
Creates a new collection instance
54 55 56 |
# File 'lib/treaty/entity/attribute/collection.rb', line 54 def initialize(collection = Set.new) @collection = collection end |
Instance Method Details
#exists? ⇒ Boolean
Checks if collection has any elements
61 62 63 |
# File 'lib/treaty/entity/attribute/collection.rb', line 61 def exists? !empty? end |