Class: DataMapper::OrderedSet

### Home Classes Methods

### In Files

- lib/dm-core/support/ordered_set.rb

### Parent

Object

### Namespace

- CLASS DataMapper::OrderedSet::Cache

### Methods

- ::new
- #<<
- #[]
- #clear
- #delete
- #each
- #empty?
- #include?
- #index
- #initialize_copy
- #merge
- #size
- #to_ary

### Included Modules

- Enumerable

### Files

- LICENSE
- README.rdoc

### Class/Module Index

Quicksearch

- DataMapper
- DataMapper::Adapters
- DataMapper::Adapters::AbstractAdapter
- DataMapper::Adapters::InMemoryAdapter
- DataMapper::Assertions
- DataMapper::Associations
- DataMapper::Associations::ManyToMany
- DataMapper::Associations::ManyToMany::Collection
- DataMapper::Associations::ManyToMany::Relationship
- DataMapper::Associations::ManyToOne
- DataMapper::Associations::ManyToOne::Relationship
- DataMapper::Associations::OneToMany
- DataMapper::Associations::OneToMany::Collection
- DataMapper::Associations::OneToMany::Relationship
- DataMapper::Associations::OneToOne
- DataMapper::Associations::OneToOne::Relationship
- DataMapper::Associations::Relationship
- DataMapper::Chainable
- DataMapper::Collection
- DataMapper::Deprecate
- DataMapper::DescendantSet
- DataMapper::Equalizer
- DataMapper::Ext
- DataMapper::Ext::Array
- DataMapper::Ext::Hash
- DataMapper::Ext::Module
- DataMapper::Ext::Object
- DataMapper::Ext::String
- DataMapper::Hook
- DataMapper::Hook::ClassMethods
- DataMapper::IdentityMap
- DataMapper::ImmutableDeletedError
- DataMapper::ImmutableError
- DataMapper::IncompleteModelError
- DataMapper::Inflector
- DataMapper::Inflector::Inflections
- DataMapper::LocalObjectSpace
- DataMapper::Logger
- DataMapper::Mash
- DataMapper::Model
- DataMapper::Model::Hook
- DataMapper::Model::Hook::MethodCommand
- DataMapper::Model::Hook::Methods
- DataMapper::Model::Hook::ProcCommand
- DataMapper::Model::Is
- DataMapper::Model::Property
- DataMapper::Model::Relationship
- DataMapper::Model::Scope
- DataMapper::NamingConventions
- DataMapper::NamingConventions::Field
- DataMapper::NamingConventions::Field::Underscored
- DataMapper::NamingConventions::Field::UnderscoredAndPluralized
- DataMapper::NamingConventions::Field::UnderscoredAndPluralizedWithoutModule
- DataMapper::NamingConventions::Field::Yaml
- DataMapper::NamingConventions::Resource
- DataMapper::NamingConventions::Resource::Underscored
- DataMapper::NamingConventions::Resource::UnderscoredAndPluralized
- DataMapper::NamingConventions::Resource::UnderscoredAndPluralizedWithoutLeadingModule
- DataMapper::NamingConventions::Resource::UnderscoredAndPluralizedWithoutModule
- DataMapper::NamingConventions::Resource::Yaml
- DataMapper::ObjectNotFoundError
- DataMapper::OrderedSet
- DataMapper::OrderedSet::Cache
- DataMapper::OrderedSet::Cache::API
- DataMapper::PersistenceError
- DataMapper::PluginNotFoundError
- DataMapper::Property
- DataMapper::Property::Binary
- DataMapper::Property::Boolean
- DataMapper::Property::Class
- DataMapper::Property::Date
- DataMapper::Property::DateTime
- DataMapper::Property::Decimal
- DataMapper::Property::Discriminator
- DataMapper::Property::Discriminator::Model
- DataMapper::Property::Float
- DataMapper::Property::Integer
- DataMapper::Property::Lookup
- DataMapper::Property::Numeric
- DataMapper::Property::Object
- DataMapper::Property::PassThroughLoadDump
- DataMapper::Property::Serial
- DataMapper::Property::String
- DataMapper::Property::Text
- DataMapper::Property::Time
- DataMapper::Property::Typecast
- DataMapper::Property::Typecast::Numeric
- DataMapper::Property::Typecast::Time
- DataMapper::PropertySet
- DataMapper::Query
- DataMapper::Query::Conditions
- DataMapper::Query::Conditions::AbstractComparison
- DataMapper::Query::Conditions::AbstractOperation
- DataMapper::Query::Conditions::AndOperation
- DataMapper::Query::Conditions::Comparison
- DataMapper::Query::Conditions::EqualToComparison
- DataMapper::Query::Conditions::FlattenOperation
- DataMapper::Query::Conditions::GreaterThanComparison
- DataMapper::Query::Conditions::GreaterThanOrEqualToComparison
- DataMapper::Query::Conditions::InclusionComparison
- DataMapper::Query::Conditions::LessThanComparison
- DataMapper::Query::Conditions::LessThanOrEqualToComparison
- DataMapper::Query::Conditions::LikeComparison
- DataMapper::Query::Conditions::NotOperation
- DataMapper::Query::Conditions::NullOperation
- DataMapper::Query::Conditions::Operation
- DataMapper::Query::Conditions::OrOperation
- DataMapper::Query::Conditions::RegexpComparison
- DataMapper::Query::Conditions::RelationshipHandler
- DataMapper::Query::Direction
- DataMapper::Query::Operator
- DataMapper::Query::Path
- DataMapper::Query::Sort
- DataMapper::RelationshipSet
- DataMapper::Repository
- DataMapper::RepositoryNotSetupError
- DataMapper::Resource
- DataMapper::Resource::PersistenceState
- DataMapper::Resource::PersistenceState::Clean
- DataMapper::Resource::PersistenceState::Deleted
- DataMapper::Resource::PersistenceState::Dirty
- DataMapper::Resource::PersistenceState::Immutable
- DataMapper::Resource::PersistenceState::Persisted
- DataMapper::Resource::PersistenceState::Transient
- DataMapper::SaveFailureError
- DataMapper::Spec
- DataMapper::Spec::Adapters
- DataMapper::Spec::Adapters::Adapter
- DataMapper::Spec::Adapters::Helpers
- DataMapper::Spec::Adapters::InMemoryAdapter
- DataMapper::Spec::CollectionHelpers
- DataMapper::Spec::CollectionHelpers::GroupMethods
- DataMapper::Spec::Helpers
- DataMapper::Spec::PendingHelpers
- DataMapper::Subject
- DataMapper::SubjectSet
- DataMapper::SubjectSet::NameCache
- DataMapper::Undefined
- DataMapper::UnknownRelationshipError
- DataMapper::UnsavedParentError
- DataMapper::UpdateConflictError
- Blog
- Blog::Article
- ChildSubType
- CounterAdapter
- Heffalump
- Kernel
- LazyArray
- Object
- OtherComparison
- Pathname
- SubType
- Symbol

No matching classes.

# DataMapper::OrderedSet

An ordered set of things

{OrderedSet} implements set behavior and keeps track of the order in which entries were added.

{OrderedSet} allows to inject a class that implements {OrderedSet::Cache::API} at construction time, and will use that cache implementation to enforce set semantics and perform internal caching of insertion order.

@see OrderedSet::Cache::API @see OrderedSet::Cache @see SubjectSet::NameCache

@api private

### Attributes

entries[R]

This set's entries

The order in this Array is not guaranteed to be the order in which the entries were inserted. Use each to access the entries in insertion order.

@return [Array]

    this set's entries

@api private

### Public Class Methods

new(entries = [], cache = Cache) click to toggle source

Initialize an OrderedSet

@param [each] entries

    the entries to initialize this set with

@param [Class<Cache::API>] cache

    the cache implementation to use

@api private

    # File lib/dm-core/support/ordered_set.rb, line 218
    def initialize(entries = [], cache = Cache)
      @cache   = cache.new
      @entries = []
      merge(entries.to_ary)
    end

### Public Instance Methods

<<(entry) click to toggle source

Add or update an entry in the set

If the entry to add isn't part of the set already, it will be added. If an entry with the same cache key as the entry to add is part of the set already, it will be replaced with the given entry.

@param [Object] entry

    the entry to be added

@return [OrderedSet] self

@api private

    # File lib/dm-core/support/ordered_set.rb, line 258
    def <<(entry)
      if index = @cache[entry]
        entries[index] = entry
      else
        @cache[entry] = size
        entries << entry
      end
      self
    end

[](index) click to toggle source

Get the entry at the given index

@param [Integer] index

    the index of the desired entry

@return [Object, nil]

    the entry at the given index, or nil if no entry is present

@api private

    # File lib/dm-core/support/ordered_set.rb, line 241
    def [](index)
      entries[index]
    end

clear() click to toggle source

Removes all entries and returns self

@return [OrderedSet] self

@api private

    # File lib/dm-core/support/ordered_set.rb, line 301
    def clear
      @cache.clear
      entries.clear
      self
    end

delete(entry) click to toggle source

Delete an entry from this OrderedSet

@param [Object] entry

    the entry to delete

@return [Object, nil]

    the deleted entry or nil

@api private

    # File lib/dm-core/support/ordered_set.rb, line 290
    def delete(entry)
      if index = @cache.delete(entry)
        entries.delete_at(index)
      end
    end

each() click to toggle source

Iterate over each entry in the set

@yield [entry]

    all entries in the set

@yieldparam [Object] entry

    an entry in the set

@return [OrderedSet] self

@api private

    # File lib/dm-core/support/ordered_set.rb, line 318
    def each
      return to_enum unless block_given?
      entries.each { |entry| yield(entry) }
      self
    end

empty?() click to toggle source

Check if there are any entries

@return [Boolean]

    true if the set is empty

@api private

    # File lib/dm-core/support/ordered_set.rb, line 340
    def empty?
      entries.empty?
    end

include?(entry) click to toggle source

Check if the entry exists in the set

@param [Object] entry

    the entry to test for

@return [Boolean]

    true if entry is included in the set

@api private

    # File lib/dm-core/support/ordered_set.rb, line 353
    def include?(entry)
      entries.include?(entry)
    end

index(entry) click to toggle source

Return the index for the entry in the set

@param [Object] entry

    the entry to check the set for

@return [Integer, nil]

    the index for the entry, or nil if it does not exist

@api private

    # File lib/dm-core/support/ordered_set.rb, line 366
    def index(entry)
      @cache[entry]
    end

initialize_copy(*) click to toggle source

Initialize a copy of OrderedSet

@api private

    # File lib/dm-core/support/ordered_set.rb, line 227
    def initialize_copy(*)
      @cache   = @cache.dup
      @entries = @entries.dup
    end

merge(other) click to toggle source

Merge with another Enumerable object

@param [each] other

    the Enumerable to merge with this OrderedSet

@return [OrderedSet] self

@api private

    # File lib/dm-core/support/ordered_set.rb, line 276
    def merge(other)
      other.each { |entry| self << entry }
      self
    end

size() click to toggle source

The number of entries

@return [Integer]

    the number of entries

@api private

    # File lib/dm-core/support/ordered_set.rb, line 330
    def size
      entries.size
    end

to_ary() click to toggle source

Convert the OrderedSet into an Array

@return [Array]

    an array containing all the OrderedSet's entries

@api private

    # File lib/dm-core/support/ordered_set.rb, line 376
    def to_ary
      entries
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.