Class: DataMapper::Adapters::AbstractAdapter
- Inherits:
-
Object
- Object
- DataMapper::Adapters::AbstractAdapter
- Extended by:
- Equalizer, Extlib::Assertions
- Includes:
- Extlib::Assertions
- Defined in:
- lib/dm-core/adapters/abstract_adapter.rb
Overview
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.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#field_naming_convention ⇒ #call
A callable object returning a naming convention for property fields.
-
#name ⇒ Symbol
readonly
Adapter name.
-
#options ⇒ Hash
readonly
Options with which adapter was set up.
-
#resource_naming_convention ⇒ #call
A callable object returning a naming convention for model storage.
Instance Method Summary collapse
-
#create(resources) ⇒ Integer
Persists one or many new resources.
-
#delete(collection) ⇒ Integer
Deletes one or many existing resources.
-
#read(query) ⇒ Enumerable<Hash>
Reads one or many resources from a datastore.
-
#update(attributes, collection) ⇒ Integer
Updates one or many existing resources.
Methods included from Equalizer
Instance Attribute Details
#field_naming_convention ⇒ #call
A callable object returning a naming convention for property fields
69 70 71 |
# File 'lib/dm-core/adapters/abstract_adapter.rb', line 69 def field_naming_convention @field_naming_convention end |
#name ⇒ Symbol (readonly)
Adapter name
Note that when you use
DataMapper.setup(:default, ‘postgres://postgres@localhost/dm_core_test’)
then adapter name is currently be set to is :default
36 37 38 |
# File 'lib/dm-core/adapters/abstract_adapter.rb', line 36 def name @name end |
#options ⇒ Hash (readonly)
Options with which adapter was set up
47 48 49 |
# File 'lib/dm-core/adapters/abstract_adapter.rb', line 47 def end |
#resource_naming_convention ⇒ #call
A callable object returning a naming convention for model storage
58 59 60 |
# File 'lib/dm-core/adapters/abstract_adapter.rb', line 58 def resource_naming_convention @resource_naming_convention end |
Instance Method Details
#create(resources) ⇒ Integer
Persists one or many new resources
Adapters provide specific implementation of this method
85 86 87 |
# File 'lib/dm-core/adapters/abstract_adapter.rb', line 85 def create(resources) raise NotImplementedError, "#{self.class}#create not implemented" end |
#delete(collection) ⇒ Integer
Deletes one or many existing resources
Adapters provide specific implementation of this method
141 142 143 |
# File 'lib/dm-core/adapters/abstract_adapter.rb', line 141 def delete(collection) raise NotImplementedError, "#{self.class}#delete not implemented" end |
#read(query) ⇒ Enumerable<Hash>
Reads one or many resources from a datastore
Adapters provide specific implementation of this method
103 104 105 |
# File 'lib/dm-core/adapters/abstract_adapter.rb', line 103 def read(query) raise NotImplementedError, "#{self.class}#read not implemented" end |
#update(attributes, collection) ⇒ Integer
Updates one or many existing resources
Adapters provide specific implementation of this method
123 124 125 |
# File 'lib/dm-core/adapters/abstract_adapter.rb', line 123 def update(attributes, collection) raise NotImplementedError, "#{self.class}#update not implemented" end |