Module: DataMapper
- Extended by:
- Assertions
- Defined in:
- lib/dm-core/query.rb,
lib/dm-core.rb,
lib/dm-core/model.rb,
lib/dm-core/version.rb,
lib/dm-core/model/is.rb,
lib/dm-core/property.rb,
lib/dm-core/resource.rb,
lib/dm-core/adapters.rb,
lib/dm-core/backwards.rb,
lib/dm-core/repository.rb,
lib/dm-core/model/hook.rb,
lib/dm-core/query/sort.rb,
lib/dm-core/spec/setup.rb,
lib/dm-core/collection.rb,
lib/dm-core/query/path.rb,
lib/dm-core/model/scope.rb,
lib/dm-core/identity_map.rb,
lib/dm-core/support/hook.rb,
lib/dm-core/property_set.rb,
lib/dm-core/support/mash.rb,
lib/dm-core/property/text.rb,
lib/dm-core/property/time.rb,
lib/dm-core/property/date.rb,
lib/dm-core/query/operator.rb,
lib/dm-core/property/float.rb,
lib/dm-core/model/property.rb,
lib/dm-core/support/logger.rb,
lib/dm-core/property/class.rb,
lib/dm-core/property/string.rb,
lib/dm-core/property/serial.rb,
lib/dm-core/property/binary.rb,
lib/dm-core/property/object.rb,
lib/dm-core/query/direction.rb,
lib/dm-core/support/subject.rb,
lib/dm-core/property/lookup.rb,
lib/dm-core/support/ext/hash.rb,
lib/dm-core/property/numeric.rb,
lib/dm-core/property/boolean.rb,
lib/dm-core/property/integer.rb,
lib/dm-core/relationship_set.rb,
lib/dm-core/property/decimal.rb,
lib/dm-core/support/ext/array.rb,
lib/dm-core/support/equalizer.rb,
lib/dm-core/support/deprecate.rb,
lib/dm-core/support/chainable.rb,
lib/dm-core/support/ext/blank.rb,
lib/dm-core/support/ext/string.rb,
lib/dm-core/support/ext/module.rb,
lib/dm-core/support/ext/object.rb,
lib/dm-core/property/date_time.rb,
lib/dm-core/model/relationship.rb,
lib/dm-core/support/assertions.rb,
lib/dm-core/support/inflections.rb,
lib/dm-core/support/ordered_set.rb,
lib/dm-core/support/subject_set.rb,
lib/dm-core/support/ext/try_dup.rb,
lib/dm-core/spec/lib/spec_helper.rb,
lib/dm-core/support/descendant_set.rb,
lib/dm-core/property/discriminator.rb,
lib/dm-core/associations/one_to_one.rb,
lib/dm-core/spec/lib/adapter_helpers.rb,
lib/dm-core/associations/many_to_one.rb,
lib/dm-core/associations/one_to_many.rb,
lib/dm-core/spec/lib/pending_helpers.rb,
lib/dm-core/adapters/abstract_adapter.rb,
lib/dm-core/support/inflector/methods.rb,
lib/dm-core/associations/many_to_many.rb,
lib/dm-core/associations/relationship.rb,
lib/dm-core/support/local_object_space.rb,
lib/dm-core/support/naming_conventions.rb,
lib/dm-core/resource/persistence_state.rb,
lib/dm-core/adapters/in_memory_adapter.rb,
lib/dm-core/query/conditions/operation.rb,
lib/dm-core/query/conditions/comparison.rb,
lib/dm-core/spec/lib/collection_helpers.rb,
lib/dm-core/property/invalid_value_error.rb,
lib/dm-core/support/inflector/inflections.rb,
lib/dm-core/resource/persistence_state/clean.rb,
lib/dm-core/resource/persistence_state/dirty.rb,
lib/dm-core/resource/persistence_state/deleted.rb,
lib/dm-core/resource/persistence_state/transient.rb,
lib/dm-core/resource/persistence_state/immutable.rb,
lib/dm-core/resource/persistence_state/persisted.rb,
lib/dm-core.rb
Overview
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.
Defined Under Namespace
Modules: Adapters, Assertions, Associations, Chainable, Deprecate, Equalizer, Ext, Hook, Inflector, LocalObjectSpace, Model, NamingConventions, Resource, Spec, Subject, Undefined Classes: Collection, DescendantSet, IdentityMap, ImmutableDeletedError, ImmutableError, IncompleteModelError, Logger, Mash, ObjectNotFoundError, OrderedSet, PersistenceError, PluginNotFoundError, Property, PropertySet, Query, RelationshipSet, Repository, RepositoryNotSetupError, SaveFailureError, SubjectSet, UnknownRelationshipError, UnsavedParentError, UpdateConflictError
Constant Summary
- VERSION =
'1.3.0.beta'
Class Attribute Summary (collapse)
-
+ (Object) logger
Returns the value of attribute logger.
Class Method Summary (collapse)
-
+ (self) finalize
Perform necessary steps to finalize DataMapper for the current repository.
-
+ (Object) repository(name = nil) {|Proc| ... }
Block Syntax.
- + (Object) root private
-
+ (DataMapper::Adapters::AbstractAdapter) setup(*args)
Setups up a connection to a data-store.
Methods included from Assertions
Class Attribute Details
+ (Object) logger
Returns the value of attribute logger
36 37 38 |
# File 'lib/dm-core/support/logger.rb', line 36 def logger @logger end |
Class Method Details
+ (self) finalize
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.
287 288 289 290 |
# File 'lib/dm-core.rb', line 287 def self.finalize Model.descendants.each { |model| model.finalize } self end |
+ (Object) repository(name = nil) {|Proc| ... }
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.
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'lib/dm-core.rb', line 256 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 |
+ (Object) root
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
212 213 214 |
# File 'lib/dm-core.rb', line 212 def self.root @root ||= Pathname(__FILE__).dirname.parent..freeze end |
+ (DataMapper::Adapters::AbstractAdapter) setup(*args)
Setups up a connection to a data-store
233 234 235 236 237 238 239 240 241 |
# File 'lib/dm-core.rb', line 233 def self.setup(*args) adapter = args.first unless adapter.kind_of?(Adapters::AbstractAdapter) adapter = Adapters.new(*args) end Repository.adapters[adapter.name] = adapter end |