Class: DataMapper::PropertySet
- Inherits:
-
Array
- Object
- Array
- DataMapper::PropertySet
- Extended by:
- Deprecate
- Defined in:
- lib/dm-core/property_set.rb
Overview
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.
Instance Method Summary collapse
-
#<<(property) ⇒ Object
TODO: document.
-
#[](name) ⇒ Object
TODO: document.
-
#[]=(name, property) ⇒ Object
TODO: document.
-
#defaults ⇒ Object
TODO: make PropertySet#reject return a PropertySet instance TODO: document.
-
#discriminator ⇒ Object
TODO: document.
-
#get(resource) ⇒ Object
TODO: document.
-
#get!(resource) ⇒ Object
TODO: document.
-
#in_context(properties) ⇒ Object
private
TODO: document.
-
#include?(property) ⇒ Boolean
TODO: document.
-
#indexes ⇒ Object
TODO: document.
-
#key ⇒ Object
TODO: document.
-
#lazy_context(context) ⇒ Object
private
TODO: document.
-
#loaded?(resource) ⇒ Boolean
TODO: document.
-
#named?(name) ⇒ Boolean
TODO: document.
-
#property_contexts(property) ⇒ Object
private
TODO: document.
-
#set(resource, values) ⇒ Object
TODO: document.
-
#set!(resource, values) ⇒ Object
TODO: document.
- #super_slice ⇒ Object
-
#typecast(values) ⇒ Object
TODO: document.
-
#unique_indexes ⇒ Object
TODO: document.
-
#values_at(*names) ⇒ Object
TODO: document.
Methods included from Deprecate
Instance Method Details
#<<(property) ⇒ Object
TODO: document
46 47 48 49 50 51 52 53 54 |
# File 'lib/dm-core/property_set.rb', line 46 def <<(property) if named?(property.name) add_property(property) super_slice(index(property), property) else add_property(property) super end end |
#[](name) ⇒ Object
TODO: document
15 16 17 |
# File 'lib/dm-core/property_set.rb', line 15 def [](name) @properties[name] end |
#[]=(name, property) ⇒ Object
TODO: document
23 24 25 26 27 28 29 30 |
# File 'lib/dm-core/property_set.rb', line 23 def []=(name, property) if named?(name) add_property(property) super_slice(index(property), property) else self << property end end |
#defaults ⇒ Object
TODO: make PropertySet#reject return a PropertySet instance TODO: document
65 66 67 |
# File 'lib/dm-core/property_set.rb', line 65 def defaults @defaults ||= self.class.new(key | [ discriminator ].compact | reject { |property| property.lazy? }).freeze end |
#discriminator ⇒ Object
TODO: document
77 78 79 |
# File 'lib/dm-core/property_set.rb', line 77 def discriminator @discriminator ||= detect { |property| property.type == Types::Discriminator } end |
#get(resource) ⇒ Object
TODO: document
99 100 101 |
# File 'lib/dm-core/property_set.rb', line 99 def get(resource) map { |property| property.get(resource) } end |
#get!(resource) ⇒ Object
TODO: document
105 106 107 |
# File 'lib/dm-core/property_set.rb', line 105 def get!(resource) map { |property| property.get!(resource) } end |
#in_context(properties) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
TODO: document
151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/dm-core/property_set.rb', line 151 def in_context(properties) properties_in_context = properties.map do |property| if (contexts = property_contexts(property)).any? lazy_contexts.values_at(*contexts) else property end end properties_in_context.flatten.uniq end |
#include?(property) ⇒ Boolean
TODO: document
58 59 60 |
# File 'lib/dm-core/property_set.rb', line 58 def include?(property) named?(property.name) end |
#indexes ⇒ Object
TODO: document
83 84 85 86 87 |
# File 'lib/dm-core/property_set.rb', line 83 def indexes index_hash = {} each { |property| parse_index(property.index, property.field, index_hash) } index_hash end |
#key ⇒ Object
TODO: document
71 72 73 |
# File 'lib/dm-core/property_set.rb', line 71 def key @key ||= self.class.new(select { |property| property.key? }).freeze end |
#lazy_context(context) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
TODO: document
145 146 147 |
# File 'lib/dm-core/property_set.rb', line 145 def lazy_context(context) lazy_contexts[context] ||= [] end |
#loaded?(resource) ⇒ Boolean
TODO: document
123 124 125 |
# File 'lib/dm-core/property_set.rb', line 123 def loaded?(resource) all? { |property| property.loaded?(resource) } end |
#named?(name) ⇒ Boolean
TODO: document
34 35 36 |
# File 'lib/dm-core/property_set.rb', line 34 def named?(name) @properties.key?(name) end |
#property_contexts(property) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
TODO: document
135 136 137 138 139 140 141 |
# File 'lib/dm-core/property_set.rb', line 135 def property_contexts(property) contexts = [] lazy_contexts.each do |context, properties| contexts << context if properties.include?(property) end contexts end |
#set(resource, values) ⇒ Object
TODO: document
111 112 113 |
# File 'lib/dm-core/property_set.rb', line 111 def set(resource, values) zip(values) { |property, value| property.set(resource, value) } end |
#set!(resource, values) ⇒ Object
TODO: document
117 118 119 |
# File 'lib/dm-core/property_set.rb', line 117 def set!(resource, values) zip(values) { |property, value| property.set!(resource, value) } end |
#super_slice ⇒ Object
19 |
# File 'lib/dm-core/property_set.rb', line 19 alias super_slice []= |
#typecast(values) ⇒ Object
TODO: document
129 130 131 |
# File 'lib/dm-core/property_set.rb', line 129 def typecast(values) zip(values.nil? ? [] : values).map { |property, value| property.typecast(value) } end |
#unique_indexes ⇒ Object
TODO: document
91 92 93 94 95 |
# File 'lib/dm-core/property_set.rb', line 91 def unique_indexes index_hash = {} each { |property| parse_index(property.unique_index, property.field, index_hash) } index_hash end |
#values_at(*names) ⇒ Object
TODO: document
40 41 42 |
# File 'lib/dm-core/property_set.rb', line 40 def values_at(*names) @properties.values_at(*names) end |