Class: DataMapper::SubjectSet

### Home Classes Methods

### In Files

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

### Parent

Object

### Namespace

- CLASS DataMapper::SubjectSet::NameCache

### Methods

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

### 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::SubjectSet

An insertion ordered set of named objects

{SubjectSet} uses {DataMapper::OrderedSet} under the hood to keep track of a set of entries. In DataMapper code, a subject can be either a {DataMapper::Property}, or a {DataMapper::Associations::Relationship}.

All entries added to instances of this class must respond to the {name} method

The motivation behind this is that we use this class as a base to keep track properties and relationships. The following constraints apply for these types of objects: {Property} names must be unique within any model. {Associations::Relationship} names must be unique within any model

When adding an entry with a name that already exists, the already existing entry will be replaced with the new entry with the same name. This is because we want to be able to update properties, and relationship during the course of initializing our application.

This also happens to be consistent with the way ruby handles redefining methods, where the last definitions "wins".

Furthermore, the builtin ruby {Set#<<} method also updates the old object if a new object gets added.

@api private

### Attributes

entries[R]

The elements in the SubjectSet

@return [OrderedSet]

@api private

### Public Class Methods

new(entries = []) click to toggle source

Initialize a SubjectSet

@param [Enumerable<name>] entries

    the entries to initialize this set with

@api private

    # File lib/dm-core/support/subject_set.rb, line 97
    def initialize(entries = [])
      @entries = OrderedSet.new(entries, NameCache)
    end

### Public Instance Methods

<<(entry) click to toggle source

Make sure that entry is part of this SubjectSet

If an entry with the same name already exists, it will be updated. If no such named entry exists, it will be added.

@param [name] entry

    the entry to be added

@return [SubjectSet] self

@api private

    # File lib/dm-core/support/subject_set.rb, line 120
    def <<(entry)
      entries << entry
      self
    end

[](name) click to toggle source

Lookup an entry in the SubjectSet based on a given name

@param [to_s] name

    the name of the entry

@return [Object, nil]

    the entry having the given name, or nil if not found

@api private

    # File lib/dm-core/support/subject_set.rb, line 193
    def [](name)
      name = name.to_s
      entries.detect { |entry| entry.name.to_s == name }
    end

clear() click to toggle source

Removes all entries and returns self

@return [SubjectSet] self

@api private

    # File lib/dm-core/support/subject_set.rb, line 143
    def clear
      entries.clear
      self
    end

delete(entry) click to toggle source

Delete an entry from this SubjectSet

@param [name] entry

    the entry to delete

@return [name, nil]

    the deleted entry or nil

@api private

    # File lib/dm-core/support/subject_set.rb, line 134
    def delete(entry)
      entries.delete(entry)
    end

each() click to toggle source

Iterate over each entry in the set

@yield [entry]

    each entry in the set

@yieldparam [name] entry

    an entry in the set

@return [SubjectSet] self

@api private

    # File lib/dm-core/support/subject_set.rb, line 209
    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 contains at least one entry

@api private

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

include?(entry) click to toggle source

Test if the given entry is included in this SubjectSet

@param [name] entry

    the entry to test for

@return [Boolean]

    true if the entry is included in this SubjectSet

@api private

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

initialize_copy(*) click to toggle source

Initialize a copy of a SubjectSet

@api private

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

named?(name) click to toggle source

Tests wether the SubjectSet contains a entry named name

@param [to_s] name

    the entry name to test for

@return [Boolean]

    true if the SubjectSet contains a entry named name

@api private

    # File lib/dm-core/support/subject_set.rb, line 170
    def named?(name)
      !self[name].nil?
    end

size() click to toggle source

Get the number of elements inside this SubjectSet

@return [Integer]

    the number of elements

@api private

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

to_ary() click to toggle source

Convert the SubjectSet into an Array

@return [Array]

    an array containing all the SubjectSet's entries

@api private

    # File lib/dm-core/support/subject_set.rb, line 246
    def to_ary
      to_a
    end

values_at(*names) click to toggle source

All entries (or nil values) that have any of the given names

@param [Enumerable<to_s>] names

    the names of the desired entries

@return [Array<name, nil>]

    an array containing entries whose names match any of the given
    names, or nil values for those names with no matching entries
    in the set

@api private

    # File lib/dm-core/support/subject_set.rb, line 226
    def values_at(*names)
      names.map { |name| self[name] }
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.