Included Modules

Class Index [+]

Quicksearch

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 {#} 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<#>] entries

  the entries to initialize this set with

@api private

    # File lib/dm-core/support/subject_set.rb, line 97
97:     def initialize(entries = [])
98:       @entries = OrderedSet.new(entries, NameCache)
99:     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 [#] entry

  the entry to be added

@return [SubjectSet] self

@api private

     # File lib/dm-core/support/subject_set.rb, line 120
120:     def <<(entry)
121:       entries << entry
122:       self
123:     end
[](name) click to toggle source

Lookup an entry in the SubjectSet based on a given name

@param [#] 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
193:     def [](name)
194:       name = name.to_s
195:       entries.detect { |entry| entry.name.to_s == name }
196:     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
143:     def clear
144:       entries.clear
145:       self
146:     end
delete(entry) click to toggle source

Delete an entry from this SubjectSet

@param [#] entry

  the entry to delete

@return [#, nil]

  the deleted entry or nil

@api private

     # File lib/dm-core/support/subject_set.rb, line 134
134:     def delete(entry)
135:       entries.delete(entry)
136:     end
each() click to toggle source

Iterate over each entry in the set

@yield [entry]

  each entry in the set

@yieldparam [#] entry

  an entry in the set

@return [SubjectSet] self

@api private

     # File lib/dm-core/support/subject_set.rb, line 209
209:     def each
210:       entries.each { |entry| yield(entry) }
211:       self
212:     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
180:     def empty?
181:       entries.empty?
182:     end
include?(entry) click to toggle source

Test if the given entry is included in this SubjectSet

@param [#] 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
157:     def include?(entry)
158:       entries.include?(entry)
159:     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
104:     def initialize_copy(*)
105:       @entries = @entries.dup
106:     end
named?(name) click to toggle source

Tests wether the SubjectSet contains a entry named name

@param [#] 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
170:     def named?(name)
171:       !self[name].nil?
172:     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 235
235:     def size
236:       entries.size
237:     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 245
245:     def to_ary
246:       to_a
247:     end
values_at(*names) click to toggle source

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

@param [Enumerable<#>] names

  the names of the desired entries

@return [Array<#, 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 225
225:     def values_at(*names)
226:       names.map { |name| self[name] }
227:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.