Parent

Included Modules

Class/Module 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
def &(other)
  self.class.new(to_a & other.to_a)
end
+(other) click to toggle source
# File lib/dm-core/property_set.rb, line 42
def +(other)
  self.class.new(to_a + other.to_a)
end
-(other) click to toggle source
# File lib/dm-core/property_set.rb, line 38
def -(other)
  self.class.new(to_a - other.to_a)
end
<<(property) click to toggle source
# File lib/dm-core/property_set.rb, line 9
def <<(property)
  clear_cache
  super
end
==(other) click to toggle source
# File lib/dm-core/property_set.rb, line 46
def ==(other)
  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/dm-core/property_set.rb, line 23
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/dm-core/property_set.rb, line 52
def defaults
  @defaults ||= self.class.new(key | [ discriminator ].compact | reject { |property| property.lazy? }).freeze
end
discriminator() click to toggle source

@api semipublic

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

@api private

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

@api semipublic

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

@api semipublic

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

@api private

# File lib/dm-core/property_set.rb, line 131
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
indexes() click to toggle source

@api semipublic

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

@api semipublic

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

@api private

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

@api semipublic

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

@api private

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

@api semipublic

# File lib/dm-core/property_set.rb, line 92
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/dm-core/property_set.rb, line 97
def set!(resource, values)
  zip(values) { |property, value| property.set!(resource, value) }
end
typecast(values) click to toggle source

@api semipublic

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

@api semipublic

# File lib/dm-core/property_set.rb, line 74
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/dm-core/property_set.rb, line 107
def valid?(values)
  zip(values.nil? ? [] : values).all? { |property, value| property.valid?(value) }
end
|(other) click to toggle source
# File lib/dm-core/property_set.rb, line 30
def |(other)
  self.class.new(to_a | other.to_a)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.