Module: DataMapper

Extended by:
Assertions
Defined in:
lib/mack-data_mapper.rb,
lib/mack-data_mapper/resource.rb,
lib/mack-data_mapper/paginator.rb,
lib/gems/dm-core-0.9.9/lib/dm-core.rb,
lib/gems/dm-types-0.9.9/lib/dm-types.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/is.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/hook.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/type.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/model.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/query.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/scope.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/types.rb,
lib/gems/dm-types-0.9.9/lib/dm-types/csv.rb,
lib/gems/dm-types-0.9.9/lib/dm-types/uri.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/logger.rb,
lib/gems/dm-types-0.9.9/lib/dm-types/enum.rb,
lib/gems/dm-types-0.9.9/lib/dm-types/flag.rb,
lib/gems/dm-types-0.9.9/lib/dm-types/json.rb,
lib/gems/dm-types-0.9.9/lib/dm-types/slug.rb,
lib/gems/dm-types-0.9.9/lib/dm-types/uuid.rb,
lib/gems/dm-types-0.9.9/lib/dm-types/yaml.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/version.rb,
lib/gems/dm-migrations-0.9.9/lib/migration.rb,
lib/gems/dm-observer-0.9.9/lib/dm-observer.rb,
lib/mack-data_mapper/dm_patches/migrations.rb,
lib/mack-data_mapper/dm_patches/migrations.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/migrator.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/property.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/resource.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/type_map.rb,
lib/gems/dm-types-0.9.9/lib/dm-types/regexp.rb,
lib/gems/dm-types-0.9.9/lib/dm-types/serial.rb,
lib/gems/dm-types-0.9.9/lib/dm-types/version.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/collection.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/repository.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/types/text.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/transaction.rb,
lib/gems/dm-timestamps-0.9.9/lib/dm-timestamps.rb,
lib/gems/dm-types-0.9.9/lib/dm-types/file_path.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/associations.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/identity_map.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/property_set.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/types/object.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/types/serial.rb,
lib/gems/dm-types-0.9.9/lib/dm-types/epoch_time.rb,
lib/gems/dm-types-0.9.9/lib/dm-types/ip_address.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/types/boolean.rb,
lib/gems/dm-types-0.9.9/lib/dm-types/bcrypt_hash.rb,
lib/gems/dm-validations-0.9.9/lib/dm-validations.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/support/errors.rb,
lib/gems/dm-migrations-0.9.9/lib/migration_runner.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/auto_migrations.rb,
lib/gems/dm-observer-0.9.9/lib/dm-observer/version.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/dependency_queue.rb,
lib/gems/dm-aggregates-0.9.9/lib/dm-aggregates/model.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/naming_conventions.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/support/assertions.rb,
lib/gems/dm-serializer-0.9.9/lib/dm-serializer/common.rb,
lib/gems/dm-serializer-0.9.9/lib/dm-serializer/to_csv.rb,
lib/gems/dm-serializer-0.9.9/lib/dm-serializer/to_xml.rb,
lib/gems/dm-aggregates-0.9.9/lib/dm-aggregates/version.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/types/discriminator.rb,
lib/gems/dm-migrations-0.9.9/lib/dm-migrations/version.rb,
lib/gems/dm-serializer-0.9.9/lib/dm-serializer/to_json.rb,
lib/gems/dm-serializer-0.9.9/lib/dm-serializer/to_yaml.rb,
lib/gems/dm-serializer-0.9.9/lib/dm-serializer/version.rb,
lib/gems/dm-timestamps-0.9.9/lib/dm-timestamps/version.rb,
lib/gems/dm-validations-0.9.9/lib/dm-validations/version.rb,
lib/gems/dm-aggregates-0.9.9/lib/dm-aggregates/collection.rb,
lib/gems/dm-aggregates-0.9.9/lib/dm-aggregates/repository.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/adapters/mysql_adapter.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/types/paranoid_boolean.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/associations/one_to_one.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/types/paranoid_datetime.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/adapters/sqlite3_adapter.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/associations/many_to_one.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/associations/one_to_many.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/adapters/abstract_adapter.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/adapters/postgres_adapter.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/associations/many_to_many.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/associations/relationship.rb,
lib/gems/dm-validations-0.9.9/lib/dm-validations/formats/url.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/adapters/in_memory_adapter.rb,
lib/gems/dm-serializer-0.9.9/lib/dm-serializer/xml_serializers.rb,
lib/gems/dm-validations-0.9.9/lib/dm-validations/auto_validate.rb,
lib/gems/dm-validations-0.9.9/lib/dm-validations/formats/email.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/adapters/data_objects_adapter.rb,
lib/gems/dm-validations-0.9.9/lib/dm-validations/block_validator.rb,
lib/gems/dm-validations-0.9.9/lib/dm-validations/custom_validator.rb,
lib/gems/dm-validations-0.9.9/lib/dm-validations/format_validator.rb,
lib/gems/dm-validations-0.9.9/lib/dm-validations/length_validator.rb,
lib/gems/dm-validations-0.9.9/lib/dm-validations/method_validator.rb,
lib/gems/dm-validations-0.9.9/lib/dm-validations/within_validator.rb,
lib/gems/dm-aggregates-0.9.9/lib/dm-aggregates/aggregate_functions.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/associations/relationship_chain.rb,
lib/gems/dm-validations-0.9.9/lib/dm-validations/generic_validator.rb,
lib/gems/dm-validations-0.9.9/lib/dm-validations/numeric_validator.rb,
lib/gems/dm-validations-0.9.9/lib/dm-validations/validation_errors.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/migrations/destructive_migrations.rb,
lib/gems/dm-serializer-0.9.9/lib/dm-serializer/xml_serializers/rexml.rb,
lib/gems/dm-validations-0.9.9/lib/dm-validations/primitive_validator.rb,
lib/gems/dm-serializer-0.9.9/lib/dm-serializer/xml_serializers/libxml.rb,
lib/gems/dm-validations-0.9.9/lib/dm-validations/acceptance_validator.rb,
lib/gems/dm-validations-0.9.9/lib/dm-validations/uniqueness_validator.rb,
lib/gems/dm-validations-0.9.9/lib/dm-validations/contextual_validators.rb,
lib/gems/dm-serializer-0.9.9/lib/dm-serializer/xml_serializers/nokogiri.rb,
lib/gems/dm-validations-0.9.9/lib/dm-validations/absent_field_validator.rb,
lib/gems/dm-validations-0.9.9/lib/dm-validations/confirmation_validator.rb,
lib/gems/dm-validations-0.9.9/lib/dm-validations/required_field_validator.rb,
lib/gems/dm-aggregates-0.9.9/lib/dm-aggregates/adapters/data_objects_adapter.rb

Overview

TODO: move to dm-more/dm-migrations

Defined Under Namespace

Modules: Adapters, AggregateFunctions, Aggregates, Assertions, Associations, AutoMigrations, DestructiveMigrations, Hook, Is, MigrationRunner, Model, NamingConventions, Observer, Resource, Scope, Serialize, Serializer, Timestamp, Timestamps, Types, Validate, Validations Classes: AutoMigrator, Collection, DependencyQueue, DestructiveMigrator, DuplicateMigrationNameError, IdentityMap, IncompleteResourceError, Logger, MaterializationError, Migration, Migrator, ObjectNotFoundError, PersistenceError, PluginNotFoundError, Property, PropertySet, Query, Repository, RepositoryNotSetupError, Transaction, Type, TypeMap, ValidationError

Constant Summary collapse

VERSION =
'0.9.9'

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Assertions

assert_kind_of

Class Attribute Details

.loggerObject

Returns the value of attribute logger.



36
37
38
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/logger.rb', line 36

def logger
  @logger
end

Class Method Details

.auto_migrate!(repository_name = nil) ⇒ Object

drops and recreates the repository upwards to match model definitions

Parameters:

  • name (Symbol)

    repository to act on, :default is the default



202
203
204
# File 'lib/gems/dm-core-0.9.9/lib/dm-core.rb', line 202

def self.auto_migrate!(repository_name = nil)
  AutoMigrator.auto_migrate(repository_name)
end

.auto_upgrade!(repository_name = nil) ⇒ Object



206
207
208
# File 'lib/gems/dm-core-0.9.9/lib/dm-core.rb', line 206

def self.auto_upgrade!(repository_name = nil)
  AutoMigrator.auto_upgrade(repository_name)
end

.dependency_queueObject



214
215
216
# File 'lib/gems/dm-core-0.9.9/lib/dm-core.rb', line 214

def self.dependency_queue
  @dependency_queue ||= DependencyQueue.new
end

.migrate!(name = Repository.default_name) ⇒ Object

destructively migrates the repository upwards to match model definitions

Parameters:

  • name (Symbol) (defaults to: Repository.default_name)

    repository to act on, :default is the default



194
195
196
# File 'lib/gems/dm-core-0.9.9/lib/dm-core.rb', line 194

def self.migrate!(name = Repository.default_name)
  repository(name).migrate!
end

.prepare(*args) {|repository(*args)| ... } ⇒ Object

Yields:



210
211
212
# File 'lib/gems/dm-core-0.9.9/lib/dm-core.rb', line 210

def self.prepare(*args, &blk)
  yield repository(*args)
end

.repository(name = nil) {|Proc| ... } ⇒ Object

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.

Parameters:

  • args (Symbol)

    the name of a repository to act within or return, :default is default

Yields:

  • (Proc)

    (optional) block to execute within the context of the named repository



172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/gems/dm-core-0.9.9/lib/dm-core.rb', line 172

def self.repository(name = nil) # :yields: current_context
  current_repository = if name
    raise ArgumentError, "First optional argument must be a Symbol, but was #{args.first.inspect}" unless name.is_a?(Symbol)
    Repository.context.detect { |r| r.name == name } || Repository.new(name)
  else
    Repository.context.last || Repository.new(Repository.default_name)
  end

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

.rootObject



108
109
110
# File 'lib/gems/dm-core-0.9.9/lib/dm-core.rb', line 108

def self.root
  @root ||= Pathname(__FILE__).dirname.parent.expand_path
end

.setup(name, uri_or_options) ⇒ Object

Setups up a connection to a data-store

-

Parameters:

Returns:

  • Repository the resulting setup repository

Raises:

  • (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>



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/gems/dm-core-0.9.9/lib/dm-core.rb', line 129

def self.setup(name, uri_or_options)
  assert_kind_of 'name',           name,           Symbol
  assert_kind_of 'uri_or_options', uri_or_options, Addressable::URI, Hash, String

  case uri_or_options
    when Hash
      adapter_name = uri_or_options[:adapter].to_s
    when String, DataObjects::URI, Addressable::URI
      uri_or_options = DataObjects::URI.parse(uri_or_options) if uri_or_options.kind_of?(String)
      adapter_name = uri_or_options.scheme
  end

  class_name = Extlib::Inflection.classify(adapter_name) + 'Adapter'

  unless Adapters::const_defined?(class_name)
    lib_name = "#{Extlib::Inflection.underscore(adapter_name)}_adapter"
    begin
      require root / 'lib' / 'dm-core' / 'adapters' / lib_name
    rescue LoadError => e
      begin
        require lib_name
      rescue Exception
        # library not found, raise the original error
        raise e
      end
    end
  end

  Repository.adapters[name] = Adapters::const_get(class_name).new(name, uri_or_options)
end

.Type(primitive_type, options = {}) ⇒ Object

class Type



156
157
158
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/type.rb', line 156

def self.Type(primitive_type, options = {})
  Class.new(Type).configure(primitive_type, options)
end