Class: DataMapper::Spec::Adapters::Adapter
- Inherits:
-
Object
- Object
- DataMapper::Spec::Adapters::Adapter
- Defined in:
- lib/dm-core/spec/setup.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #adapter ⇒ Object (also: #setup)
- #adapter_name ⇒ Object
- #alternate_storage_name ⇒ Object
- #connection_uri ⇒ Object
- #default_storage_name ⇒ Object
- #host ⇒ Object
-
#initialize(name) ⇒ Adapter
constructor
A new instance of Adapter.
- #password ⇒ Object
- #setup! ⇒ Object
- #storage_name ⇒ Object
-
#test_connection(adapter) ⇒ Object
Test the connection.
- #username ⇒ Object
Constructor Details
#initialize(name) ⇒ Adapter
Returns a new instance of Adapter.
95 96 97 |
# File 'lib/dm-core/spec/setup.rb', line 95 def initialize(name) @name = name.to_sym end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
93 94 95 |
# File 'lib/dm-core/spec/setup.rb', line 93 def name @name end |
Instance Method Details
#adapter ⇒ Object Also known as: setup
99 100 101 |
# File 'lib/dm-core/spec/setup.rb', line 99 def adapter @adapter ||= setup! end |
#adapter_name ⇒ Object
113 114 115 |
# File 'lib/dm-core/spec/setup.rb', line 113 def adapter_name @adapter_name ||= infer_adapter_name end |
#alternate_storage_name ⇒ Object
129 130 131 |
# File 'lib/dm-core/spec/setup.rb', line 129 def alternate_storage_name "datamapper_alternate_tests" end |
#connection_uri ⇒ Object
117 118 119 |
# File 'lib/dm-core/spec/setup.rb', line 117 def connection_uri "#{adapter_name}://#{username}:#{password}@#{host}/#{storage_name}" end |
#default_storage_name ⇒ Object
125 126 127 |
# File 'lib/dm-core/spec/setup.rb', line 125 def default_storage_name "datamapper_default_tests" end |
#host ⇒ Object
141 142 143 |
# File 'lib/dm-core/spec/setup.rb', line 141 def host ENV.fetch('DM_DB_HOST', 'localhost') end |
#password ⇒ Object
137 138 139 |
# File 'lib/dm-core/spec/setup.rb', line 137 def password ENV.fetch('DM_DB_PASSWORD', 'datamapper') end |
#setup! ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/dm-core/spec/setup.rb', line 105 def setup! adapter = DataMapper.setup(name, connection_uri) test_connection(adapter) adapter rescue Exception => e puts "Could not connect to the database using '#{connection_uri}' because of: #{e.inspect}" end |
#storage_name ⇒ Object
121 122 123 |
# File 'lib/dm-core/spec/setup.rb', line 121 def storage_name send("#{name}_storage_name") end |
#test_connection(adapter) ⇒ Object
Test the connection
Overwrite this method if you need to perform custom connection testing
150 151 152 153 154 |
# File 'lib/dm-core/spec/setup.rb', line 150 def test_connection(adapter) if adapter.respond_to?(:select) adapter.select('SELECT 1') end end |
#username ⇒ Object
133 134 135 |
# File 'lib/dm-core/spec/setup.rb', line 133 def username ENV.fetch('DM_DB_USER', 'datamapper') end |