Class: DataMapper::PropertySet

### Home Classes Methods

### In Files

- lib/dm-core/property_set.rb

### Parent

SubjectSet

### Methods

- #&
- #+
- #-
- #<<
- #==
- #[]=
- #defaults
- #discriminator
- #field_map
- #get
- #get!
- #in_context
- #indexes
- #inspect
- #key
- #lazy_context
- #loaded?
- #property_contexts
- #set
- #set!
- #typecast
- #unique_indexes
- #valid?
- #|

### Included Modules

- Enumerable

### Files

- LICENSE
- README.rdoc

### Class/Module Index

Quicksearch

- DataMapper
- DataMapper::Adapters
- DataMapper::Adapters::AbstractAdapter
- DataMapper::Adapters::InMemoryAdapter
- DataMapper::Assertions
- DataMapper::Associations
- DataMapper::Associations::ManyToMany
- DataMapper::Associations::ManyToMany::Collection
- DataMapper::Associations::ManyToMany::Relationship
- DataMapper::Associations::ManyToOne
- DataMapper::Associations::ManyToOne::Relationship
- DataMapper::Associations::OneToMany
- DataMapper::Associations::OneToMany::Collection
- DataMapper::Associations::OneToMany::Relationship
- DataMapper::Associations::OneToOne
- DataMapper::Associations::OneToOne::Relationship
- DataMapper::Associations::Relationship
- DataMapper::Chainable
- DataMapper::Collection
- DataMapper::Deprecate
- DataMapper::DescendantSet
- DataMapper::Equalizer
- DataMapper::Ext
- DataMapper::Ext::Array
- DataMapper::Ext::Hash
- DataMapper::Ext::Module
- DataMapper::Ext::Object
- DataMapper::Ext::String
- DataMapper::Hook
- DataMapper::Hook::ClassMethods
- DataMapper::IdentityMap
- DataMapper::ImmutableDeletedError
- DataMapper::ImmutableError
- DataMapper::IncompleteModelError
- DataMapper::Inflector
- DataMapper::Inflector::Inflections
- DataMapper::LocalObjectSpace
- DataMapper::Logger
- DataMapper::Mash
- DataMapper::Model
- DataMapper::Model::Hook
- DataMapper::Model::Hook::MethodCommand
- DataMapper::Model::Hook::Methods
- DataMapper::Model::Hook::ProcCommand
- DataMapper::Model::Is
- DataMapper::Model::Property
- DataMapper::Model::Relationship
- DataMapper::Model::Scope
- DataMapper::NamingConventions
- DataMapper::NamingConventions::Field
- DataMapper::NamingConventions::Field::Underscored
- DataMapper::NamingConventions::Field::UnderscoredAndPluralized
- DataMapper::NamingConventions::Field::UnderscoredAndPluralizedWithoutModule
- DataMapper::NamingConventions::Field::Yaml
- DataMapper::NamingConventions::Resource
- DataMapper::NamingConventions::Resource::Underscored
- DataMapper::NamingConventions::Resource::UnderscoredAndPluralized
- DataMapper::NamingConventions::Resource::UnderscoredAndPluralizedWithoutLeadingModule
- DataMapper::NamingConventions::Resource::UnderscoredAndPluralizedWithoutModule
- DataMapper::NamingConventions::Resource::Yaml
- DataMapper::ObjectNotFoundError
- DataMapper::OrderedSet
- DataMapper::OrderedSet::Cache
- DataMapper::OrderedSet::Cache::API
- DataMapper::PersistenceError
- DataMapper::PluginNotFoundError
- DataMapper::Property
- DataMapper::Property::Binary
- DataMapper::Property::Boolean
- DataMapper::Property::Class
- DataMapper::Property::Date
- DataMapper::Property::DateTime
- DataMapper::Property::Decimal
- DataMapper::Property::Discriminator
- DataMapper::Property::Discriminator::Model
- DataMapper::Property::Float
- DataMapper::Property::Integer
- DataMapper::Property::Lookup
- DataMapper::Property::Numeric
- DataMapper::Property::Object
- DataMapper::Property::PassThroughLoadDump
- DataMapper::Property::Serial
- DataMapper::Property::String
- DataMapper::Property::Text
- DataMapper::Property::Time
- DataMapper::Property::Typecast
- DataMapper::Property::Typecast::Numeric
- DataMapper::Property::Typecast::Time
- DataMapper::PropertySet
- DataMapper::Query
- DataMapper::Query::Conditions
- DataMapper::Query::Conditions::AbstractComparison
- DataMapper::Query::Conditions::AbstractOperation
- DataMapper::Query::Conditions::AndOperation
- DataMapper::Query::Conditions::Comparison
- DataMapper::Query::Conditions::EqualToComparison
- DataMapper::Query::Conditions::FlattenOperation
- DataMapper::Query::Conditions::GreaterThanComparison
- DataMapper::Query::Conditions::GreaterThanOrEqualToComparison
- DataMapper::Query::Conditions::InclusionComparison
- DataMapper::Query::Conditions::LessThanComparison
- DataMapper::Query::Conditions::LessThanOrEqualToComparison
- DataMapper::Query::Conditions::LikeComparison
- DataMapper::Query::Conditions::NotOperation
- DataMapper::Query::Conditions::NullOperation
- DataMapper::Query::Conditions::Operation
- DataMapper::Query::Conditions::OrOperation
- DataMapper::Query::Conditions::RegexpComparison
- DataMapper::Query::Conditions::RelationshipHandler
- DataMapper::Query::Direction
- DataMapper::Query::Operator
- DataMapper::Query::Path
- DataMapper::Query::Sort
- DataMapper::RelationshipSet
- DataMapper::Repository
- DataMapper::RepositoryNotSetupError
- DataMapper::Resource
- DataMapper::Resource::PersistenceState
- DataMapper::Resource::PersistenceState::Clean
- DataMapper::Resource::PersistenceState::Deleted
- DataMapper::Resource::PersistenceState::Dirty
- DataMapper::Resource::PersistenceState::Immutable
- DataMapper::Resource::PersistenceState::Persisted
- DataMapper::Resource::PersistenceState::Transient
- DataMapper::SaveFailureError
- DataMapper::Spec
- DataMapper::Spec::Adapters
- DataMapper::Spec::Adapters::Adapter
- DataMapper::Spec::Adapters::Helpers
- DataMapper::Spec::Adapters::InMemoryAdapter
- DataMapper::Spec::CollectionHelpers
- DataMapper::Spec::CollectionHelpers::GroupMethods
- DataMapper::Spec::Helpers
- DataMapper::Spec::PendingHelpers
- DataMapper::Subject
- DataMapper::SubjectSet
- DataMapper::SubjectSet::NameCache
- DataMapper::Undefined
- DataMapper::UnknownRelationshipError
- DataMapper::UnsavedParentError
- DataMapper::UpdateConflictError
- Blog
- Blog::Article
- ChildSubType
- CounterAdapter
- Heffalump
- Kernel
- LazyArray
- Object
- OtherComparison
- Pathname
- SubType
- Symbol

No matching classes.

# 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.