Class: DataMapper::Adapters::AbstractAdapter

Class | DataMapper::Adapters::AbstractAdapter
In: | lib/dm-core/adapters/abstract_adapter.rb
Parent: | Object

Specific adapters extend this class and implement methods for creating, reading, updating and deleting records.

Adapters may only implement method for reading or (less common case) writing. Read only adapter may be useful when one needs to work with legacy data that should not be changed or web services that only provide read access to data (from Wordnet and Medline to Atom and RSS syndication feeds)

Note that in case of adapters to relational databases it makes sense to inherit from DataObjectsAdapter class.

### Methods

attributes_as_fields create delete initialize_serial new read update

### Included Modules

Extlib::Assertions

### Attributes

field_naming_convention | [RW] | A callable object returning a naming convention for property fields @example
      adapter.field_naming_convention  # => Proc for field name
@return [call]
      object to return the naming convention for each field
@api semipublic
name | [R] | Adapter name @example
      adapter.name  # => :default
Note that when you use DataMapper.setup(:default, ‘postgres://postgres@localhost/dm_core_test’) then adapter name is currently be set to is :default @return [Symbol]
      the adapter name
@api semipublic
options | [R] | Options with which adapter was set up @example
      adapter.options  # => { :adapter => 'yaml', :path => '/tmp' }
@return [Hash]
      adapter configuration options
@api semipublic
resource_naming_convention | [RW] | A callable object returning a naming convention for model storage @example
      adapter.resource_naming_convention  # => Proc for model storage name
@return [call]
      object to return the naming convention for each model
@api semipublic

### Public Class methods

new(name, options)

Initialize an AbstractAdapter instance

@param [Symbol] name

      the adapter repository name

@param [Hash] options

      the adapter configuration options

@return [undefined]

@api semipublic

### Public Instance methods

create(resources)

Persists one or many new resources

@example

      adapter.create(collection)  # => 1

Adapters provide specific implementation of this method

@param [Enumerable<Resource>] resources

      The list of resources (model instances) to create

@return [Integer]

      The number of records that were actually saved into the data-store

@api semipublic

delete(collection)

Deletes one or many existing resources

@example

      adapter.delete(collection)  # => 1

Adapters provide specific implementation of this method

@param [Collection] collection

      collection of records to be deleted

@return [Integer]

      the number of records deleted

@api semipublic

read(query)

Reads one or many resources from a datastore

@example

      adapter.read(query)  # => [ { 'name' => 'Dan Kubb' } ]

Adapters provide specific implementation of this method

@param [Query] query

      the query to match resources in the datastore

@return [Enumerable<Hash>]

      an array of hashes to become resources

@api semipublic

update(attributes, collection)

Updates one or many existing resources

@example

      adapter.update(attributes, collection)  # => 1

Adapters provide specific implementation of this method

@param [Hash(Property => Object)] attributes

      hash of attribute values to set, keyed by Property

@param [Collection] collection

      collection of records to be updated

@return [Integer]

      the number of records updated

@api semipublic

### Protected Instance methods

attributes_as_fields(attributes)

Translate the attributes into a Hash with the field as the key

@example

      attributes = { User.properties[:name] => 'Dan Kubb' }
      adapter.attributes_as_fields(attributes)  # => { 'name' => 'Dan Kubb' }

@param [Hash] attributes

      the attributes with the Property as the key

@return [Hash]

      the attributes with the Property#field as the key

@api semipublic

initialize_serial(resource, next_id)

Set the serial value of the Resource

@param [Resource] resource

      the resource to set the serial property in

@param [Integer] id

      the identifier to set in the resource

@return [undefined]

@api semipublic

[Validate]