In Files

Class Index [+]

Quicksearch

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


TODO: rename # to #


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 # and # 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
280:   def self.finalize
281:     Model.descendants.each { |model| model.finalize }
282:     self
283:   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
249:   def self.repository(name = nil)
250:     context = Repository.context
251: 
252:     current_repository = if name
253:       name = name.to_sym
254:       context.detect { |repository| repository.name == name }
255:     else
256:       name = Repository.default_name
257:       context.last
258:     end
259: 
260:     current_repository ||= Repository.new(name)
261: 
262:     if block_given?
263:       current_repository.scope { |*block_args| yield(*block_args) }
264:     else
265:       current_repository
266:     end
267:   end
root() click to toggle source

@api private

     # File lib/dm-core.rb, line 205
205:   def self.root
206:     @root ||= Pathname(__FILE__).dirname.parent.expand_path.freeze
207:   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
226:   def self.setup(*args)
227:     adapter = args.first
228: 
229:     unless adapter.kind_of?(Adapters::AbstractAdapter)
230:       adapter = Adapters.new(*args)
231:     end
232: 
233:     Repository.adapters[adapter.name] = adapter
234:   end

Public Instance Methods

object_by_id(object_id) click to toggle source
    # File lib/dm-core/support/local_object_space.rb, line 8
 8:     def object_by_id(object_id)
 9:       self.hook_scopes.detect { |object| object.object_id == object_id }
10:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.