Class: Treaty::Attribute::Collection
- Inherits:
-
Object
- Object
- Treaty::Attribute::Collection
- Extended by:
- Forwardable
- Defined in:
- lib/treaty/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 attribute
-
‘each`, `map`, `select`, `reject` - Iteration
-
‘find`, `first` - Access
-
‘size`, `empty?` - Size checks
-
‘to_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
53 54 55 |
# File 'lib/treaty/attribute/collection.rb', line 53 def initialize(collection = Set.new) @collection = collection end |
Instance Method Details
#exists? ⇒ Boolean
Checks if collection has any elements
60 61 62 |
# File 'lib/treaty/attribute/collection.rb', line 60 def exists? !empty? end |