Class: DataMapper::Adapters::AbstractAdapter
- Object
- DataMapper::Adapters::AbstractAdapter
Attributes
Instance Attributes
| field_naming_convention | [RW] | public |
Sets the attribute field_naming_convention. |
|---|---|---|---|
| name | [RW] | public |
Returns the value of attribute name. |
| resource_naming_convention | [RW] | public |
Sets the attribute resource_naming_convention. |
| uri | [RW] | public |
Returns the value of attribute uri. |
Constructor Summary
Instantiate an Adapter by passing it a DataMapper::Repository connection string for configuration.
197 198 199 200 201 202 203 204 205 206 207 208
# File 'dm-core/lib/dm-core/adapters/abstract_adapter.rb', line 197 def initialize(name, uri_or_options) raise ArgumentError, "+name+ should be a Symbol, but was #{name.class}", caller unless Symbol === name raise ArgumentError, "+uri_or_options+ should be a Hash, a Addressable::URI or a String but was #{uri_or_options.class}", caller unless [ Hash, Addressable::URI, String ].any? { |k| k === uri_or_options } @name = name @uri = normalize_uri(uri_or_options) @resource_naming_convention = NamingConventions::UnderscoredAndPluralized @field_naming_convention = NamingConventions::Underscored @transactions = Hash.new { |hash, key| hash[key] = [] } end
Public Visibility
Public Class Method Summary
| type_map |
Default TypeMap for all adapters. Returns: |
|---|
Public Instance Method Summary
| #alter_model_storage(repository, *args) |
TODO: move to dm-more/dm-migrations. |
|---|---|
| #alter_property_storage(repository, *args) |
TODO: move to dm-more/dm-migrations. |
| #create(repository, resource) |
Methods dealing with a single resource object. |
| #create_model_storage(repository, model) |
TODO: move to dm-more/dm-migrations. |
| #create_property_storage(repository, property) |
TODO: move to dm-more/dm-migrations. |
| #current_transaction |
Retrieve the current transaction for this Adapter. Returns: |
| #delete(repository, resource) | |
| #delete_set(repository, query) | |
| #destroy_model_storage(repository, model) |
TODO: move to dm-more/dm-migrations. |
| #destroy_property_storage(repository, property) |
TODO: move to dm-more/dm-migrations. |
| #field_exists?(storage_name, field_name) |
Returns whether the field exists. Returns: |
| #pop_transaction |
Pop the ‘current’ Transaction from the per thread Transaction stack so that everything done by this Adapter is no longer necessarily within the context of said Transaction. Returns: |
| #push_transaction(transaction) |
methods dealing with transactions. |
| #read(repository, resource, key) | |
| #read_one(repository, query) |
Methods dealing with locating a single object, by keys. |
| #read_set(repository, query) |
Methods dealing with finding stuff by some query parameters. |
| #storage_exists?(storage_name) |
Deprecated in favor of read_one def first(repository, resource, query = {}) raise ArgumentError, "You cannot pass in a :limit option to #first" if query. Returns: |
| #transaction_primitive |
Produces a fresh transaction primitive for this Adapter. Returns: |
| #update(repository, resource) | |
| #upgrade_model_storage(repository, model) |
TODO: move to dm-more/dm-migrations. |
| #within_transaction? |
Returns whether we are within a Transaction. Returns: |
Public Instance Methods Inherited from Object
Public Class Method Details
type_map
Default TypeMap for all adapters.
9 10 11 12 13 14
# File 'dm-core/lib/dm-core/adapters/abstract_adapter.rb', line 9 def self.type_map @type_map ||= TypeMap.new end
Public Instance Method Details
alter_model_storage
TODO: move to dm-more/dm-migrations
105 106 107
# File 'dm-core/lib/dm-core/adapters/abstract_adapter.rb', line 105 def alter_model_storage(repository, *args) raise NotImplementedError end
alter_property_storage
TODO: move to dm-more/dm-migrations
120 121 122
# File 'dm-core/lib/dm-core/adapters/abstract_adapter.rb', line 120 def alter_property_storage(repository, *args) raise NotImplementedError end
create
Methods dealing with a single resource object
17 18 19
# File 'dm-core/lib/dm-core/adapters/abstract_adapter.rb', line 17 def create(repository, resource) raise NotImplementedError end
create_model_storage
TODO: move to dm-more/dm-migrations
95 96 97
# File 'dm-core/lib/dm-core/adapters/abstract_adapter.rb', line 95 def create_model_storage(repository, model) raise NotImplementedError end
create_property_storage
TODO: move to dm-more/dm-migrations
110 111 112
# File 'dm-core/lib/dm-core/adapters/abstract_adapter.rb', line 110 def create_property_storage(repository, property) raise NotImplementedError end
current_transaction
Retrieve the current transaction for this Adapter.
Everything done by this Adapter is done within the context of this Transaction.
160 161 162 163 164 165
# File 'dm-core/lib/dm-core/adapters/abstract_adapter.rb', line 160 def current_transaction @transactions[Thread.current].last end
delete
29 30 31
# File 'dm-core/lib/dm-core/adapters/abstract_adapter.rb', line 29 def delete(repository, resource) raise NotImplementedError end
delete_set
43 44 45
# File 'dm-core/lib/dm-core/adapters/abstract_adapter.rb', line 43 def delete_set(repository, query) raise NotImplementedError end
destroy_model_storage
TODO: move to dm-more/dm-migrations
100 101 102
# File 'dm-core/lib/dm-core/adapters/abstract_adapter.rb', line 100 def destroy_model_storage(repository, model) raise NotImplementedError end
destroy_property_storage
TODO: move to dm-more/dm-migrations
115 116 117
# File 'dm-core/lib/dm-core/adapters/abstract_adapter.rb', line 115 def destroy_property_storage(repository, property) raise NotImplementedError end
field_exists?
Returns whether the field exists.
85 86 87
# File 'dm-core/lib/dm-core/adapters/abstract_adapter.rb', line 85 def field_exists?(storage_name, field_name) raise NotImplementedError end
pop_transaction
Pop the ‘current’ Transaction from the per thread Transaction stack so that everything done by this Adapter is no longer necessarily within the context of said Transaction.
147 148 149 150 151 152
# File 'dm-core/lib/dm-core/adapters/abstract_adapter.rb', line 147 def pop_transaction @transactions[Thread.current].pop end
push_transaction
methods dealing with transactions
Pushes the given Transaction onto the per thread Transaction stack so that everything done by this Adapter is done within the context of said Transaction.
135 136 137
# File 'dm-core/lib/dm-core/adapters/abstract_adapter.rb', line 135 def push_transaction(transaction) @transactions[Thread.current] << transaction end
read
21 22 23
# File 'dm-core/lib/dm-core/adapters/abstract_adapter.rb', line 21 def read(repository, resource, key) raise NotImplementedError end
read_one
Methods dealing with locating a single object, by keys
34 35 36
# File 'dm-core/lib/dm-core/adapters/abstract_adapter.rb', line 34 def read_one(repository, query) raise NotImplementedError end
read_set
Methods dealing with finding stuff by some query parameters
39 40 41
# File 'dm-core/lib/dm-core/adapters/abstract_adapter.rb', line 39 def read_set(repository, query) raise NotImplementedError end
storage_exists?
Deprecated in favor of read_one def first(repository, resource, query = {})
raise ArgumentError, "You cannot pass in a :limit option to #first" if query.key?(:limit) read_set(repository, resource, query.merge(:limit => 1)).first
end Future Enumerable/convenience finders. Please leave in place. :-) def each(repository, klass, query)
raise NotImplementedError raise ArgumentError unless block_given?
end
Returns whether the storage_name exists.
69 70 71
# File 'dm-core/lib/dm-core/adapters/abstract_adapter.rb', line 69 def storage_exists?(storage_name) raise NotImplementedError end
transaction_primitive
Produces a fresh transaction primitive for this Adapter
Used by DataMapper::Transaction to perform its various tasks.
183 184 185 186 187 188
# File 'dm-core/lib/dm-core/adapters/abstract_adapter.rb', line 183 def transaction_primitive raise NotImplementedError end
update
25 26 27
# File 'dm-core/lib/dm-core/adapters/abstract_adapter.rb', line 25 def update(repository, resource) raise NotImplementedError end
upgrade_model_storage
TODO: move to dm-more/dm-migrations
90 91 92
# File 'dm-core/lib/dm-core/adapters/abstract_adapter.rb', line 90 def upgrade_model_storage(repository, model) raise NotImplementedError end
within_transaction?
Returns whether we are within a Transaction.
170 171 172 173 174 175
# File 'dm-core/lib/dm-core/adapters/abstract_adapter.rb', line 170 def within_transaction? !current_transaction.nil? end
Protected Visibility
Protected Instance Method Summary
| #normalize_uri(uri_or_options) |
|---|
Protected Instance Method Details
normalize_uri
189 190 191
# File 'dm-core/lib/dm-core/adapters/abstract_adapter.rb', line 189 def normalize_uri(uri_or_options) uri_or_options end