Module: DataMapper

### Home Classes Methods

### In Files

- lib/dm-core.rb
- lib/dm-core/adapters.rb
- lib/dm-core/adapters/abstract_adapter.rb
- lib/dm-core/adapters/in_memory_adapter.rb
- lib/dm-core/associations/many_to_many.rb
- lib/dm-core/associations/many_to_one.rb
- lib/dm-core/associations/one_to_many.rb
- lib/dm-core/associations/one_to_one.rb
- lib/dm-core/associations/relationship.rb
- lib/dm-core/backwards.rb
- lib/dm-core/collection.rb
- lib/dm-core/identity_map.rb
- lib/dm-core/model.rb
- lib/dm-core/model/hook.rb
- lib/dm-core/model/is.rb
- lib/dm-core/model/property.rb
- lib/dm-core/model/relationship.rb
- lib/dm-core/model/scope.rb
- lib/dm-core/property.rb
- lib/dm-core/property/binary.rb
- lib/dm-core/property/boolean.rb
- lib/dm-core/property/class.rb
- lib/dm-core/property/date.rb
- lib/dm-core/property/date_time.rb
- lib/dm-core/property/decimal.rb
- lib/dm-core/property/discriminator.rb
- lib/dm-core/property/float.rb
- lib/dm-core/property/integer.rb
- lib/dm-core/property/lookup.rb
- lib/dm-core/property/numeric.rb
- lib/dm-core/property/object.rb
- lib/dm-core/property/serial.rb
- lib/dm-core/property/string.rb
- lib/dm-core/property/text.rb
- lib/dm-core/property/time.rb
- lib/dm-core/property/typecast/numeric.rb
- lib/dm-core/property/typecast/time.rb
- lib/dm-core/property_set.rb
- lib/dm-core/query.rb
- lib/dm-core/query/conditions/comparison.rb
- lib/dm-core/query/conditions/operation.rb
- lib/dm-core/query/direction.rb
- lib/dm-core/query/operator.rb
- lib/dm-core/query/path.rb
- lib/dm-core/query/sort.rb
- lib/dm-core/relationship_set.rb
- lib/dm-core/repository.rb
- lib/dm-core/resource.rb
- lib/dm-core/resource/persistence_state.rb
- lib/dm-core/resource/persistence_state/clean.rb
- lib/dm-core/resource/persistence_state/deleted.rb
- lib/dm-core/resource/persistence_state/dirty.rb
- lib/dm-core/resource/persistence_state/immutable.rb
- lib/dm-core/resource/persistence_state/persisted.rb
- lib/dm-core/resource/persistence_state/transient.rb
- lib/dm-core/spec/lib/adapter_helpers.rb
- lib/dm-core/spec/lib/collection_helpers.rb
- lib/dm-core/spec/lib/pending_helpers.rb
- lib/dm-core/spec/lib/spec_helper.rb
- lib/dm-core/spec/setup.rb
- lib/dm-core/support/assertions.rb
- lib/dm-core/support/chainable.rb
- lib/dm-core/support/deprecate.rb
- lib/dm-core/support/descendant_set.rb
- lib/dm-core/support/equalizer.rb
- lib/dm-core/support/ext/array.rb
- lib/dm-core/support/ext/blank.rb
- lib/dm-core/support/ext/hash.rb
- lib/dm-core/support/ext/module.rb
- lib/dm-core/support/ext/object.rb
- lib/dm-core/support/ext/string.rb
- lib/dm-core/support/ext/try_dup.rb
- lib/dm-core/support/hook.rb
- lib/dm-core/support/inflections.rb
- lib/dm-core/support/inflector/inflections.rb
- lib/dm-core/support/inflector/methods.rb
- lib/dm-core/support/local_object_space.rb
- lib/dm-core/support/logger.rb
- lib/dm-core/support/mash.rb
- lib/dm-core/support/naming_conventions.rb
- lib/dm-core/support/ordered_set.rb
- lib/dm-core/support/subject.rb
- lib/dm-core/support/subject_set.rb
- lib/dm-core/version.rb

### Namespace

- MODULE DataMapper::Adapters
- MODULE DataMapper::Assertions
- MODULE DataMapper::Associations
- MODULE DataMapper::Chainable
- MODULE DataMapper::Deprecate
- MODULE DataMapper::Equalizer
- MODULE DataMapper::Ext
- MODULE DataMapper::Hook
- MODULE DataMapper::Inflector
- MODULE DataMapper::LocalObjectSpace
- MODULE DataMapper::Model
- MODULE DataMapper::NamingConventions
- MODULE DataMapper::Resource
- MODULE DataMapper::Spec
- MODULE DataMapper::Subject
- MODULE DataMapper::Undefined
- CLASS DataMapper::Collection
- CLASS DataMapper::DescendantSet
- CLASS DataMapper::IdentityMap
- CLASS DataMapper::ImmutableDeletedError
- CLASS DataMapper::ImmutableError
- CLASS DataMapper::IncompleteModelError
- CLASS DataMapper::Logger
- CLASS DataMapper::Mash
- CLASS DataMapper::ObjectNotFoundError
- CLASS DataMapper::OrderedSet
- CLASS DataMapper::PersistenceError
- CLASS DataMapper::PluginNotFoundError
- CLASS DataMapper::Property
- CLASS DataMapper::PropertySet
- CLASS DataMapper::Query
- CLASS DataMapper::RelationshipSet
- CLASS DataMapper::Repository
- CLASS DataMapper::RepositoryNotSetupError
- CLASS DataMapper::SaveFailureError
- CLASS DataMapper::SubjectSet
- CLASS DataMapper::UnknownRelationshipError
- CLASS DataMapper::UnsavedParentError
- CLASS DataMapper::UpdateConflictError

### Methods

- ::finalize
- ::repository
- ::root
- ::setup

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

## Setup and Configuration

DataMapper uses URIs or a connection hash to connect to your data-store. URI connections takes the form of:

    DataMapper.setup(:default, 'protocol://username:password@localhost:port/path/to/repo')

Breaking this down, the first argument is the name you wish to give this connection. If you do not specify one, it will be assigned :default. If you would like to connect to more than one data-store, simply issue this command again, but with a different name specified.

In order to issue ORM commands without specifying the repository context, you must define the :default database. Otherwise, you'll need to wrap your ORM calls in `repository(:name) { }`.

Second, the URI breaks down into the access protocol, the username, the server, the password, and whatever path information is needed to properly address the data-store on the server.

Here's some examples

    DataMapper.setup(:default, 'sqlite3://path/to/your/project/db/development.db')
    DataMapper.setup(:default, 'mysql://localhost/dm_core_test')
      # no auth-info
    DataMapper.setup(:default, 'postgres://root:supahsekret@127.0.0.1/dm_core_test')
      # with auth-info

Alternatively, you can supply a hash as the second parameter, which would take the form:

    DataMapper.setup(:default, {
      :adapter  => 'adapter_name_here',
      :database => 'path/to/repo',
      :username => 'username',
      :password => 'password',
      :host     => 'hostname'
    })

### Logging

To turn on error logging to STDOUT, issue:

    DataMapper::Logger.new($stdout, :debug)

You can pass a file location ("/path/to/log/file.log") in place of $stdout. see DataMapper::Logger for more information.

TODO: move argument and option validation into the class

TODO: move Collection#loaded_entries to LazyArray TODO: move Collection#partially_loaded to LazyArray

TODO: update Model#respond_to? to return true if method_method missing would handle the message

TODO: update Model#respond_to? to return true if method_method missing would handle the message

TODO: move condition transformations into a Query::Conditions

    helper class that knows how to transform the primitives, and
    calls #comparison_for(repository, model) on objects (or some
    other convention that we establish)

TODO: remove get method

TODO: rename target to property_name

TODO: instead of an Array of Path objects, create a Relationship on the fly using :through on the previous relationship, creating a chain. Query::Path could then be a thin wrapper that specifies extra conditions on the Relationships, like the target property o match on.

TODO: add reverse and reverse! methods

#### Public DataMapper Logger API

To replace an existing logger with a new one:

    DataMapper::Logger.set_log(log{String, IO},level{Symbol, String})

Available logging levels are

    DataMapper::Logger::{ Fatal, Error, Warn, Info, Debug }

Logging via:

    DataMapper.logger.fatal(message<String>,&block)
    DataMapper.logger.error(message<String>,&block)
    DataMapper.logger.warn(message<String>,&block)
    DataMapper.logger.info(message<String>,&block)
    DataMapper.logger.debug(message<String>,&block)

Logging with autoflush:

    DataMapper.logger.fatal!(message<String>,&block)
    DataMapper.logger.error!(message<String>,&block)
    DataMapper.logger.warn!(message<String>,&block)
    DataMapper.logger.info!(message<String>,&block)
    DataMapper.logger.debug!(message<String>,&block)

Flush the buffer to

    DataMapper.logger.flush

Remove the current log object

    DataMapper.logger.close

#### Private DataMapper Logger API

To initialize the logger you create a new object, proxies to set_log.

    DataMapper::Logger.new(log{String, IO},level{Symbol, String})

### Constants

VERSION

### Attributes

logger[RW]

### Public Class Methods

finalize() click to toggle source

Perform necessary steps to finalize DataMapper for the current repository

This method should be called after loading all models and plugins.

It ensures foreign key properties and anonymous join models are created. These are otherwise lazily declared, which can lead to unexpected errors. It also performs basic validity checking of the DataMapper models.

@return [DataMapper] The DataMapper module

@api public

    # File lib/dm-core.rb, line 280
    def self.finalize
      Model.descendants.each { |model| model.finalize }
      self
    end

repository(name = nil) click to toggle source

Block Syntax

    Pushes the named repository onto the context-stack,
    yields a new session, and pops the context-stack.

Non-Block Syntax

    Returns the current session, or if there is none,
    a new Session.

@param [Symbol] args the name of a repository to act within or return, :default is default

@yield [Proc] (optional) block to execute within the context of the named repository

@api public

    # File lib/dm-core.rb, line 249
    def self.repository(name = nil)
      context = Repository.context

      current_repository = if name
        name = name.to_sym
        context.detect { |repository| repository.name == name }
      else
        name = Repository.default_name
        context.last
      end

      current_repository ||= Repository.new(name)

      if block_given?
        current_repository.scope { |*block_args| yield(*block_args) }
      else
        current_repository
      end
    end

root() click to toggle source

@api private

    # File lib/dm-core.rb, line 205
    def self.root
      @root ||= Pathname(__FILE__).dirname.parent.expand_path.freeze
    end

setup(*args) click to toggle source

Setups up a connection to a data-store

@param [Symbol] name

    a name for the context, defaults to :default

@param [Hash(Symbol => String), Addressable::URI, String] uri_or_options

    connection information

@return [DataMapper::Adapters::AbstractAdapter]

    the resulting setup adapter

@raise [ArgumentError] "`name` must be a Symbol, but was..."

    indicates that an invalid argument was passed for name[Symbol]

@raise [ArgumentError] "`uri_or_options` must be a Hash, URI or String, but was..."

    indicates that connection information could not be gleaned from
    the given uri_or_options[Hash, Addressable::URI, String]

@api public

    # File lib/dm-core.rb, line 226
    def self.setup(*args)
      adapter = args.first

      unless adapter.kind_of?(Adapters::AbstractAdapter)
        adapter = Adapters.new(*args)
      end

      Repository.adapters[adapter.name] = adapter
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.