Class: Motel::ConnectionAdapters::ConnectionSpecification::Resolver
- Inherits:
-
Object
- Object
- Motel::ConnectionAdapters::ConnectionSpecification::Resolver
- Defined in:
- lib/motel/connection_adapters/connection_specification/resolver.rb
Instance Attribute Summary collapse
-
#configurations ⇒ Object
Returns the value of attribute configurations.
Instance Method Summary collapse
-
#initialize(configurations = nil) ⇒ Resolver
constructor
A new instance of Resolver.
- #spec(config) ⇒ Object
Constructor Details
#initialize(configurations = nil) ⇒ Resolver
Returns a new instance of Resolver.
12 13 14 |
# File 'lib/motel/connection_adapters/connection_specification/resolver.rb', line 12 def initialize(configurations = nil) @configurations = configurations || {} end |
Instance Attribute Details
#configurations ⇒ Object
Returns the value of attribute configurations.
10 11 12 |
# File 'lib/motel/connection_adapters/connection_specification/resolver.rb', line 10 def configurations @configurations end |
Instance Method Details
#spec(config) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/motel/connection_adapters/connection_specification/resolver.rb', line 16 def spec(config) spec = resolve(config).symbolize_keys raise(::ActiveRecord::AdapterNotSpecified, "database configuration does not specify adapter") unless spec.key?(:adapter) path_to_adapter = "active_record/connection_adapters/#{spec[:adapter]}_adapter" begin require path_to_adapter rescue Gem::LoadError => e raise Gem::LoadError, "Specified '#{spec[:adapter]}' for database adapter, but the gem is not loaded. Add `gem '#{e.name}'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord)." rescue LoadError => e raise LoadError, "Could not load '#{path_to_adapter}'. Make sure that the adapter in config/database.yml is valid. If you use an adapter other than 'mysql', 'mysql2', 'postgresql' or 'sqlite3' add the necessary adapter gem to the Gemfile.", e.backtrace end adapter_method = "#{spec[:adapter]}_connection" ::ActiveRecord::ConnectionAdapters::ConnectionSpecification.new(spec, adapter_method) end |