Class: DataMapper::Adapters::AbstractAdapter
- Inherits:
-
Object
- Object
- DataMapper::Adapters::AbstractAdapter
- Defined in:
- lib/data_mapper/adapters/abstract_adapter.rb
Overview
You must inherit from the Abstract::Adapter, and implement the required methods to adapt a database library for use with the DataMapper.
NOTE: By inheriting from AbstractAdapter, you get a copy of all the standard sub-modules (Quoting, Coersion and Queries) in your own Adapter. You can extend and overwrite these copies without affecting the originals.
Direct Known Subclasses
Defined Under Namespace
Modules: Coersion, Queries, Quoting
Constant Summary collapse
- TYPES =
{ :integer => 'int'.freeze, :string => 'varchar'.freeze, :text => 'text'.freeze, :class => 'varchar'.freeze }
- SYNTAX =
{ :auto_increment => 'auto_increment'.freeze }
Class Method Summary collapse
-
.inherited(base) ⇒ Object
This callback copies and sub-classes modules and classes in the AbstractAdapter to the inherited class so you don’t have to copy and paste large blocks of code from the AbstractAdapter.
Instance Method Summary collapse
- #connection(&block) ⇒ Object
-
#initialize(configuration) ⇒ AbstractAdapter
constructor
Instantiate an Adapter by passing it a DataMapper::Database object for configuration.
- #transaction(&block) ⇒ Object
Constructor Details
#initialize(configuration) ⇒ AbstractAdapter
Instantiate an Adapter by passing it a DataMapper::Database object for configuration.
50 51 52 |
# File 'lib/data_mapper/adapters/abstract_adapter.rb', line 50 def initialize(configuration) @configuration = configuration end |
Class Method Details
.inherited(base) ⇒ Object
This callback copies and sub-classes modules and classes in the AbstractAdapter to the inherited class so you don’t have to copy and paste large blocks of code from the AbstractAdapter.
Basically, when inheriting from the AbstractAdapter, you aren’t just inheriting a single class, you’re inheriting a whole graph of Types. For convenience.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/data_mapper/adapters/abstract_adapter.rb', line 70 def self.inherited(base) quoting = base.const_set('Quoting', Module.new) quoting.send(:include, Quoting) coersion = base.const_set('Coersion', Module.new) coersion.send(:include, Coersion) queries = base.const_set('Queries', Module.new) Queries.constants.each do |name| queries.const_set(name, Class.new(Queries.const_get(name))) end base.const_set('TYPES', TYPES.dup) base.const_set('SYNTAX', SYNTAX.dup) end |
Instance Method Details
#connection(&block) ⇒ Object
54 55 56 |
# File 'lib/data_mapper/adapters/abstract_adapter.rb', line 54 def connection(&block) raise NotImplementedError.new end |
#transaction(&block) ⇒ Object
58 59 60 |
# File 'lib/data_mapper/adapters/abstract_adapter.rb', line 58 def transaction(&block) raise NotImplementedError.new end |