Class: Treaty::Entity::Attribute::Collection

Inherits:
Object
  • Object
show all
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 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

Constructor Details

#initialize(collection = Set.new) ⇒ Collection

Creates a new collection instance

Parameters:

  • collection (Set) (defaults to: Set.new)

    Initial collection (default: empty Set)



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

Returns:

  • (Boolean)

    True if collection is not empty



61
62
63
# File 'lib/treaty/entity/attribute/collection.rb', line 61

def exists?
  !empty?
end