Included Modules

Class Index [+]

Quicksearch

DataMapper::PropertySet

Set of Property objects, used to associate queries with set of fields it performed over, to represent composite keys (esp. for associations) and so on.

Public Instance Methods

&(other) click to toggle source
    # File lib/dm-core/property_set.rb, line 34
34:     def &(other)
35:       self.class.new(to_a & other.to_a)
36:     end
+(other) click to toggle source
    # File lib/dm-core/property_set.rb, line 42
42:     def +(other)
43:       self.class.new(to_a + other.to_a)
44:     end
-(other) click to toggle source
    # File lib/dm-core/property_set.rb, line 38
38:     def -(other)
39:       self.class.new(to_a - other.to_a)
40:     end
<<(property) click to toggle source
    # File lib/dm-core/property_set.rb, line 9
 9:     def <<(property)
10:       clear_cache
11:       super
12:     end
==(other) click to toggle source
    # File lib/dm-core/property_set.rb, line 46
46:     def ==(other)
47:       to_a == other.to_a
48:     end
[]=(name, entry) click to toggle source

Make sure that entry is part of this PropertySet

@param [#] name @param [#] entry

@return [#]

  the entry that is now part of this PropertySet

@api semipublic

    # File lib/dm-core/property_set.rb, line 23
23:     def []=(name, entry)
24:       warn "#{self.class}#[]= is deprecated. Use #{self.class}#<< instead: #{caller.first}"
25:       raise "#{entry.class} is not added with the correct name" unless name && name.to_s == entry.name.to_s
26:       self << entry
27:       entry
28:     end
defaults() click to toggle source

TODO: make PropertySet#reject return a PropertySet instance @api semipublic

    # File lib/dm-core/property_set.rb, line 52
52:     def defaults
53:       @defaults ||= self.class.new(key | [ discriminator ].compact | reject { |property| property.lazy? }).freeze
54:     end
discriminator() click to toggle source

@api semipublic

    # File lib/dm-core/property_set.rb, line 62
62:     def discriminator
63:       @discriminator ||= detect { |property| property.kind_of?(Property::Discriminator) }
64:     end
field_map() click to toggle source

@api private

     # File lib/dm-core/property_set.rb, line 144
144:     def field_map
145:       Hash[ map { |property| [ property.field, property ] } ]
146:     end
get(resource) click to toggle source

@api semipublic

    # File lib/dm-core/property_set.rb, line 81
81:     def get(resource)
82:       return [] if resource.nil?
83:       map { |property| resource.__send__(property.name) }
84:     end
get!(resource) click to toggle source

@api semipublic

    # File lib/dm-core/property_set.rb, line 87
87:     def get!(resource)
88:       map { |property| property.get!(resource) }
89:     end
in_context(properties) click to toggle source

@api private

     # File lib/dm-core/property_set.rb, line 131
131:     def in_context(properties)
132:       properties_in_context = properties.map do |property|
133:         if (contexts = property_contexts(property)).any?
134:           lazy_contexts.values_at(*contexts)
135:         else
136:           property
137:         end
138:       end
139: 
140:       properties_in_context.flatten.uniq
141:     end
indexes() click to toggle source

@api semipublic

    # File lib/dm-core/property_set.rb, line 67
67:     def indexes
68:       index_hash = {}
69:       each { |property| parse_index(property.index, property.field, index_hash) }
70:       index_hash
71:     end
inspect() click to toggle source
     # File lib/dm-core/property_set.rb, line 148
148:     def inspect
149:       to_a.inspect
150:     end
key() click to toggle source

@api semipublic

    # File lib/dm-core/property_set.rb, line 57
57:     def key
58:       @key ||= self.class.new(select { |property| property.key? }).freeze
59:     end
lazy_context(context) click to toggle source

@api private

     # File lib/dm-core/property_set.rb, line 126
126:     def lazy_context(context)
127:       lazy_contexts[context] ||= []
128:     end
loaded?(resource) click to toggle source

@api semipublic

     # File lib/dm-core/property_set.rb, line 102
102:     def loaded?(resource)
103:       all? { |property| property.loaded?(resource) }
104:     end
property_contexts(property) click to toggle source

@api private

     # File lib/dm-core/property_set.rb, line 117
117:     def property_contexts(property)
118:       contexts = []
119:       lazy_contexts.each do |context, properties|
120:         contexts << context if properties.include?(property)
121:       end
122:       contexts
123:     end
set(resource, values) click to toggle source

@api semipublic

    # File lib/dm-core/property_set.rb, line 92
92:     def set(resource, values)
93:       zip(values) { |property, value| resource.__send__("#{property.name}=", value) }
94:     end
set!(resource, values) click to toggle source

@api semipublic

    # File lib/dm-core/property_set.rb, line 97
97:     def set!(resource, values)
98:       zip(values) { |property, value| property.set!(resource, value) }
99:     end
typecast(values) click to toggle source

@api semipublic

     # File lib/dm-core/property_set.rb, line 112
112:     def typecast(values)
113:       zip(values.nil? ? [] : values).map { |property, value| property.typecast(value) }
114:     end
unique_indexes() click to toggle source

@api semipublic

    # File lib/dm-core/property_set.rb, line 74
74:     def unique_indexes
75:       index_hash = {}
76:       each { |property| parse_index(property.unique_index, property.field, index_hash) }
77:       index_hash
78:     end
valid?(values) click to toggle source

@api semipublic

     # File lib/dm-core/property_set.rb, line 107
107:     def valid?(values)
108:       zip(values.nil? ? [] : values).all? { |property, value| property.valid?(value) }
109:     end
|(other) click to toggle source
    # File lib/dm-core/property_set.rb, line 30
30:     def |(other)
31:       self.class.new(to_a | other.to_a)
32:     end

Private Instance Methods

clear_cache() click to toggle source

@api private

     # File lib/dm-core/property_set.rb, line 155
155:     def clear_cache
156:       @defaults, @key, @discriminator = nil
157:     end
lazy_contexts() click to toggle source

@api private

     # File lib/dm-core/property_set.rb, line 160
160:     def lazy_contexts
161:       @lazy_contexts ||= {}
162:     end
parse_index(index, property, index_hash) click to toggle source

@api private

     # File lib/dm-core/property_set.rb, line 165
165:     def parse_index(index, property, index_hash)
166:       case index
167:         when true
168:           index_hash[property] = [ property ]
169:         when Symbol
170:           index_hash[index] ||= []
171:           index_hash[index] << property
172:         when Array
173:           index.each { |idx| parse_index(idx, property, index_hash) }
174:       end
175:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.