Module: DataMapper::Model::Property

### Home Classes Methods

### In Files

- lib/dm-core/model/property.rb

### Methods

- ::extended
- #field_naming_convention
- #inherited
- #key
- #key_conditions
- #properties
- #properties_with_subclasses
- #property
- #serial

### 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::Model::Property

### Public Class Methods

extended(model) click to toggle source

    # File lib/dm-core/model/property.rb, line 9
    def self.extended(model)
      model.instance_variable_set(:@properties,               {})
      model.instance_variable_set(:@field_naming_conventions, {})
    end

### Public Instance Methods

field_naming_convention(repository_name = default_storage_name) click to toggle source

Gets the field naming conventions for this resource in the given Repository

@param [String, Symbol] repository_name

    the name of the Repository for which the field naming convention
    will be retrieved

@return [call]

    The naming convention for the given Repository

@api public

    # File lib/dm-core/model/property.rb, line 159
    def field_naming_convention(repository_name = default_storage_name)
      @field_naming_conventions[repository_name] ||= repository(repository_name).adapter.field_naming_convention
    end

inherited(model) click to toggle source

    # File lib/dm-core/model/property.rb, line 15
    def inherited(model)
      model.instance_variable_set(:@properties,               {})
      model.instance_variable_set(:@field_naming_conventions, @field_naming_conventions.dup)

      @properties.each do |repository_name, properties|
        model_properties = model.properties(repository_name)
        properties.each { |property| model_properties << property }
      end

      super
    end

key(repository_name = default_repository_name) click to toggle source

Gets the list of key fields for this Model in `repository_name`

@param [String] repository_name

    The name of the Repository for which the key is to be reported

@return [Array]

    The list of key fields for this Model in +repository_name+

@api public

    # File lib/dm-core/model/property.rb, line 140
    def key(repository_name = default_repository_name)
      properties(repository_name).key
    end

key_conditions(repository, key) click to toggle source

@api private

    # File lib/dm-core/model/property.rb, line 177
    def key_conditions(repository, key)
      Hash[ self.key(repository.name).zip(key.nil? ? [] : key) ]
    end

properties(repository_name = default_repository_name) click to toggle source

Gets a list of all properties that have been defined on this Model in the requested repository

@param [Symbol, String] repository_name

    The name of the repository to use. Uses the default Repository
    if none is specified.

@return [PropertySet]

    A list of Properties defined on this Model in the given Repository

@api public

    # File lib/dm-core/model/property.rb, line 116
    def properties(repository_name = default_repository_name)
      # TODO: create PropertySet#copy that will copy the properties, but assign the
      # new Relationship objects to a supplied repository and model.  dup does not really
      # do what is needed
      repository_name = repository_name.to_sym

      default_repository_name = self.default_repository_name

      @properties[repository_name] ||= if repository_name == default_repository_name
        PropertySet.new
      else
        properties(default_repository_name).dup
      end
    end

properties_with_subclasses(repository_name = default_repository_name) click to toggle source

@api private

    # File lib/dm-core/model/property.rb, line 164
    def properties_with_subclasses(repository_name = default_repository_name)
      properties = properties(repository_name).dup

      descendants.each do |model|
        model.properties(repository_name).each do |property|
          properties << property
        end
      end

      properties
    end

property(name, type, options = {}) click to toggle source

Defines a Property on the Resource

@param [Symbol] name

    the name for which to call this property

@param [Class] type

    the ruby type to define this property as

@param [Hash(Symbol => String)] options

    a hash of available options

@return [Property]

    the created Property

@see Property

@api public

    # File lib/dm-core/model/property.rb, line 42
    def property(name, type, options = {})
      if TrueClass == type
        raise "#{type} is deprecated, use Boolean instead at #{caller[2]}"
      elsif BigDecimal == type
        raise "#{type} is deprecated, use Decimal instead at #{caller[2]}"
      end

      # if the type can be found within Property then
      # use that class rather than the primitive
      unless klass = DataMapper::Property.determine_class(type)
        raise ArgumentError, "+type+ was #{type.inspect}, which is not a supported type"
      end

      property = klass.new(self, name, options)

      repository_name = self.repository_name
      properties      = properties(repository_name)

      properties << property

      # Add property to the other mappings as well if this is for the default
      # repository.

      if repository_name == default_repository_name
        other_repository_properties = DataMapper::Ext::Hash.except(@properties, default_repository_name)

        other_repository_properties.each do |other_repository_name, properties|
          next if properties.named?(name)

          # make sure the property is created within the correct repository scope
          DataMapper.repository(other_repository_name) do
            properties << klass.new(self, name, options)
          end
        end
      end

      # Add the property to the lazy_loads set for this resources repository
      # only.
      # TODO Is this right or should we add the lazy contexts to all
      # repositories?
      if property.lazy?
        context = options.fetch(:lazy, :default)
        context = :default if context == true

        Array(context).each do |context|
          properties.lazy_context(context) << property
        end
      end

      # add the property to the child classes only if the property was
      # added after the child classes' properties have been copied from
      # the parent
      descendants.each do |descendant|
        descendant.properties(repository_name) << property
      end

      create_reader_for(property)
      create_writer_for(property)

      # FIXME: explicit return needed for YARD to parse this properly
      return property
    end

serial(repository_name = default_repository_name) click to toggle source

@api public

    # File lib/dm-core/model/property.rb, line 145
    def serial(repository_name = default_repository_name)
      key(repository_name).detect { |property| property.serial? }
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.