Class | DataMapper::SubjectSet |
In: |
lib/dm-core/support/subject_set.rb
|
Parent: | Object |
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
entries | [R] |
The elements in the SubjectSet
@return [OrderedSet] @api private |
Initialize a SubjectSet
@param [Enumerable<name>] entries
the entries to initialize this set with
@api private
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
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
Delete an entry from this SubjectSet
@param [name] entry
the entry to delete
@return [name, nil]
the deleted entry or nil
@api private
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
Check if there are any entries
@return [Boolean]
true if the set contains at least one entry
@api private
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
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
Get the number of elements inside this SubjectSet
@return [Integer]
the number of elements
@api private
Convert the SubjectSet into an Array
@return [Array]
an array containing all the SubjectSet's entries
@api private
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