class Ardm::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/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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
Calls superclass method
# File lib/ardm/property_set.rb, line 12 def <<(property) clear_cache super end
==(other)
click to toggle source
# File lib/ardm/property_set.rb, line 53 def ==(other) other.respond_to?(:to_a) && to_a == other.to_a end
[]=(name, entry)
click to toggle source
Make sure that entry is part of this PropertySet
@param [#to_s] name @param [#name] entry
@return [#name]
the entry that is now part of this PropertySet
@api semipublic
# 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()
click to toggle source
TODO: make PropertySet#reject return a PropertySet
instance @api semipublic
# File lib/ardm/property_set.rb, line 59 def defaults @defaults ||= self.class.new(key | [ discriminator ].compact | reject { |property| property.lazy? }).freeze end
discriminator()
click to toggle source
@api semipublic
# File lib/ardm/property_set.rb, line 69 def discriminator @discriminator ||= detect { |property| property.kind_of?(Property::Discriminator) } end
field_map()
click to toggle source
@api private
# File lib/ardm/property_set.rb, line 124 def field_map Hash[ map { |property| [ property.field, property ] } ] end
get(resource)
click to toggle source
@api semipublic
# File lib/ardm/property_set.rb, line 88 def get(resource) return [] if resource.nil? map { |property| resource.__send__(property.name) } end
get!(resource)
click to toggle source
@api semipublic
# File lib/ardm/property_set.rb, line 94 def get!(resource) map { |property| property.get!(resource) } end
indexes()
click to toggle source
@api semipublic
# 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()
click to toggle source
# File lib/ardm/property_set.rb, line 128 def inspect to_a.inspect end
key()
click to toggle source
@api semipublic
# File lib/ardm/property_set.rb, line 64 def key @key ||= self.class.new(select { |property| property.key? }).freeze end
loaded?(resource)
click to toggle source
@api semipublic
# File lib/ardm/property_set.rb, line 109 def loaded?(resource) all? { |property| property.loaded?(resource) } end
set(resource, values)
click to toggle source
@api semipublic
# 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)
click to toggle source
@api semipublic
# File lib/ardm/property_set.rb, line 104 def set!(resource, values) zip(values) { |property, value| property.set!(resource, value) } end
typecast(values)
click to toggle source
@api semipublic
# File lib/ardm/property_set.rb, line 119 def typecast(values) zip(values.nil? ? [] : values).map { |property, value| property.typecast(value) } end
unique_indexes()
click to toggle source
@api semipublic
# 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)
click to toggle source
@api semipublic
# File lib/ardm/property_set.rb, line 114 def valid?(values) zip(values.nil? ? [] : values).all? { |property, value| property.valid?(value) } end
|(other)
click to toggle source
# 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
Private Instance Methods
clear_cache()
click to toggle source
@api private
# File lib/ardm/property_set.rb, line 135 def clear_cache @defaults, @key, @discriminator = nil end
parse_index(index, property, index_hash)
click to toggle source
@api private
# File lib/ardm/property_set.rb, line 140 def parse_index(index, property, index_hash) case index when true index_hash[property] = [ property ] when Symbol index_hash[index] ||= [] index_hash[index] << property when Array index.each { |idx| parse_index(idx, property, index_hash) } end end