Class: Ardm::PropertySet
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 Attribute Summary
Attributes inherited from SubjectSet
#entries
Instance Method Summary
collapse
Methods inherited from SubjectSet
#[], #clear, #delete, #each, #empty?, #include?, #initialize, #initialize_copy, #named?, #size, #to_ary, #values_at
Instance Method Details
#&(other) ⇒ Object
38
39
40
41
|
# File 'lib/ardm/property_set.rb', line 38
def &(other)
raise(ArgumentError, "Cannot coerce #{other.inspect} into an array") unless other.respond_to?(:to_a)
self.class.new(to_a & other.to_a)
end
|
#+(other) ⇒ Object
48
49
50
51
|
# File 'lib/ardm/property_set.rb', line 48
def +(other)
raise(ArgumentError, "Cannot coerce #{other.inspect} into an array") unless other.respond_to?(:to_a)
self.class.new(to_a + other.to_a)
end
|
#-(other) ⇒ Object
43
44
45
46
|
# File 'lib/ardm/property_set.rb', line 43
def -(other)
raise(ArgumentError, "Cannot coerce #{other.inspect} into an array") unless other.respond_to?(:to_a)
self.class.new(to_a - other.to_a)
end
|
#<<(property) ⇒ Object
12
13
14
15
|
# File 'lib/ardm/property_set.rb', line 12
def <<(property)
clear_cache
super
end
|
#==(other) ⇒ Object
53
54
55
|
# File 'lib/ardm/property_set.rb', line 53
def ==(other)
other.respond_to?(:to_a) && to_a == other.to_a
end
|
#[]=(name, entry) ⇒ #name
Make sure that entry is part of this PropertySet
26
27
28
29
30
31
|
# File 'lib/ardm/property_set.rb', line 26
def []=(name, entry)
warn "#{self.class}#[]= is deprecated. Use #{self.class}#<< instead: #{caller.first}"
raise "#{entry.class} is not added with the correct name" unless name && name.to_s == entry.name.to_s
self << entry
entry
end
|
#defaults ⇒ Object
TODO: make PropertySet#reject return a PropertySet instance
59
60
61
|
# File 'lib/ardm/property_set.rb', line 59
def defaults
@defaults ||= self.class.new(key | [ discriminator ].compact | reject { |property| property.lazy? }).freeze
end
|
#discriminator ⇒ Object
69
70
71
|
# File 'lib/ardm/property_set.rb', line 69
def discriminator
@discriminator ||= detect { |property| property.kind_of?(Property::Discriminator) }
end
|
#field_map ⇒ 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.
124
125
126
|
# File 'lib/ardm/property_set.rb', line 124
def field_map
Hash[ map { |property| [ property.field, property ] } ]
end
|
#get(resource) ⇒ Object
88
89
90
91
|
# File 'lib/ardm/property_set.rb', line 88
def get(resource)
return [] if resource.nil?
map { |property| resource.__send__(property.name) }
end
|
#get!(resource) ⇒ Object
94
95
96
|
# File 'lib/ardm/property_set.rb', line 94
def get!(resource)
map { |property| property.get!(resource) }
end
|
#indexes ⇒ Object
74
75
76
77
78
|
# File 'lib/ardm/property_set.rb', line 74
def indexes
index_hash = {}
each { |property| parse_index(property.index, property.field, index_hash) }
index_hash
end
|
#inspect ⇒ Object
128
129
130
|
# File 'lib/ardm/property_set.rb', line 128
def inspect
to_a.inspect
end
|
#key ⇒ Object
64
65
66
|
# File 'lib/ardm/property_set.rb', line 64
def key
@key ||= self.class.new(select { |property| property.key? }).freeze
end
|
#loaded?(resource) ⇒ Boolean
109
110
111
|
# File 'lib/ardm/property_set.rb', line 109
def loaded?(resource)
all? { |property| property.loaded?(resource) }
end
|
#set(resource, values) ⇒ Object
99
100
101
|
# File 'lib/ardm/property_set.rb', line 99
def set(resource, values)
zip(values) { |property, value| resource.__send__("#{property.name}=", value) }
end
|
#set!(resource, values) ⇒ Object
104
105
106
|
# File 'lib/ardm/property_set.rb', line 104
def set!(resource, values)
zip(values) { |property, value| property.set!(resource, value) }
end
|
#typecast(values) ⇒ Object
119
120
121
|
# File 'lib/ardm/property_set.rb', line 119
def typecast(values)
zip(values.nil? ? [] : values).map { |property, value| property.typecast(value) }
end
|
#unique_indexes ⇒ Object
81
82
83
84
85
|
# File 'lib/ardm/property_set.rb', line 81
def unique_indexes
index_hash = {}
each { |property| parse_index(property.unique_index, property.field, index_hash) }
index_hash
end
|
#valid?(values) ⇒ Boolean
114
115
116
|
# File 'lib/ardm/property_set.rb', line 114
def valid?(values)
zip(values.nil? ? [] : values).all? { |property, value| property.valid?(value) }
end
|
#|(other) ⇒ Object
33
34
35
36
|
# File 'lib/ardm/property_set.rb', line 33
def |(other)
raise(ArgumentError, "Cannot coerce #{other.inspect} into an array") unless other.respond_to?(:to_a)
self.class.new(to_a | other.to_a)
end
|