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

private initialize(name, uri_or_options)

Instantiate an Adapter by passing it a DataMapper::Repository connection string for configuration.

[View source]


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

validatable?

Public Class Method Details

type_map

public type_map

Default TypeMap for all adapters.

Meta Tags

Returns:

<DataMapper::TypeMap> default TypeMap

[View source]


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

public alter_model_storage(repository, *args)

TODO: move to dm-more/dm-migrations

[View source]


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

public alter_property_storage(repository, *args)

TODO: move to dm-more/dm-migrations

[View source]


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

public create(repository, resource)

Methods dealing with a single resource object

[View source]


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

public create_model_storage(repository, model)

TODO: move to dm-more/dm-migrations

[View source]


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

public create_property_storage(repository, property)

TODO: move to dm-more/dm-migrations

[View source]


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

public current_transaction

Retrieve the current transaction for this Adapter.

Everything done by this Adapter is done within the context of this Transaction.

Meta Tags

Returns:

<DataMapper::Transaction> the ‘current’ transaction for this Adapter.

TODO: move to dm-more/dm-transaction

[View source]


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

public delete(repository, resource)
[View source]


29
30
31
# File 'dm-core/lib/dm-core/adapters/abstract_adapter.rb', line 29

def delete(repository, resource)
  raise NotImplementedError
end

delete_set

public delete_set(repository, query)
[View source]


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

public destroy_model_storage(repository, model)

TODO: move to dm-more/dm-migrations

[View source]


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

public destroy_property_storage(repository, property)

TODO: move to dm-more/dm-migrations

[View source]


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?

public field_exists?(storage_name, field_name)

Returns whether the field exists.

Meta Tags

Parameters:

storage_name<String>

a String defining the name of a storage, for example a table name.

field_name<String>

a String defining the name of a field, for example a column name.

Returns:

<Boolean> true if the field exists.

TODO: move to dm-more/dm-migrations (if possible)

[View source]


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

public 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.

Meta Tags

Returns:

<DataMapper::Transaction> the former ‘current’ transaction.

TODO: move to dm-more/dm-transaction

[View source]


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

public push_transaction(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.

Meta Tags

Parameters:

transaction<DataMapper::Transaction>

a Transaction to be the ‘current’ transaction until popped.

TODO: move to dm-more/dm-transaction

[View source]


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

public read(repository, resource, key)
[View source]


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

public read_one(repository, query)

Methods dealing with locating a single object, by keys

[View source]


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

public read_set(repository, query)

Methods dealing with finding stuff by some query parameters

[View source]


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?

public 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.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.

Meta Tags

Parameters:

storage_name<String>

a String defining the name of a storage, for example a table name.

Returns:

<Boolean> true if the storage exists

TODO: move to dm-more/dm-migrations (if possible)

[View source]


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

public transaction_primitive

Produces a fresh transaction primitive for this Adapter

Used by DataMapper::Transaction to perform its various tasks.

Meta Tags

Returns:

<Object> a new Object that responds to :close, :begin, :commit, :rollback, :rollback_prepared and :prepare

TODO: move to dm-more/dm-transaction (if possible)

[View source]


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

public update(repository, resource)
[View source]


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

public upgrade_model_storage(repository, model)

TODO: move to dm-more/dm-migrations

[View source]


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?

public within_transaction?

Returns whether we are within a Transaction.

Meta Tags

Returns:

<Boolean> whether we are within a Transaction.

TODO: move to dm-more/dm-transaction

[View source]


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

protected normalize_uri(uri_or_options)
[View source]


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