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.
88 89 90 |
# File 'lib/dm-core/spec/setup.rb', line 88 def initialize(name) @name = name.to_sym end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
86 87 88 |
# File 'lib/dm-core/spec/setup.rb', line 86 def name @name end |
Instance Method Details
#adapter ⇒ Object Also known as: setup
92 93 94 |
# File 'lib/dm-core/spec/setup.rb', line 92 def adapter @adapter ||= setup! end |
#adapter_name ⇒ Object
106 107 108 |
# File 'lib/dm-core/spec/setup.rb', line 106 def adapter_name @adapter_name ||= infer_adapter_name end |
#alternate_storage_name ⇒ Object
124 125 126 |
# File 'lib/dm-core/spec/setup.rb', line 124 def alternate_storage_name 'datamapper_alternate_tests' end |
#connection_uri ⇒ Object
110 111 112 113 114 |
# File 'lib/dm-core/spec/setup.rb', line 110 def connection_uri "#{adapter_name}://#{username}%s@#{host}/#{storage_name}".tap do |s| return s % (password.empty? ? '' : ":#{password}") end end |
#default_storage_name ⇒ Object
120 121 122 |
# File 'lib/dm-core/spec/setup.rb', line 120 def default_storage_name 'datamapper_default_tests' end |
#host ⇒ Object
136 137 138 |
# File 'lib/dm-core/spec/setup.rb', line 136 def host ENV.fetch('DM_DB_HOST', '127.0.0.1') end |
#password ⇒ Object
132 133 134 |
# File 'lib/dm-core/spec/setup.rb', line 132 def password ENV.fetch('DM_DB_PASSWORD', 'datamapper') end |
#setup! ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/dm-core/spec/setup.rb', line 98 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
116 117 118 |
# File 'lib/dm-core/spec/setup.rb', line 116 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
145 146 147 148 149 |
# File 'lib/dm-core/spec/setup.rb', line 145 def test_connection(adapter) return unless adapter.respond_to?(:select) adapter.select('SELECT 1') end |
#username ⇒ Object
128 129 130 |
# File 'lib/dm-core/spec/setup.rb', line 128 def username ENV.fetch('DM_DB_USER', 'datamapper') end |