Class: ActiveRecord::Base::ConnectionSpecification::Resolver

Inherits:
Object
  • Object
show all
Defined in:
lib/activerecord-futures.rb

Instance Method Summary collapse

Instance Method Details

#spec_with_futuresObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/activerecord-futures.rb', line 32

def spec_with_futures
  spec = spec_without_futures
  begin
    config = spec.config
    future_adapter_name = "future_enabled_#{config[:adapter]}"

    # Try to load the future version of the adapter
    require "active_record/connection_adapters/#{future_adapter_name}_adapter"

    config[:adapter] = future_adapter_name
    adapter_method = "future_enabled_#{spec.adapter_method}"

    # Return the specification with the future adapter instead
    ActiveRecord::Base::ConnectionSpecification.new(config, adapter_method)
  rescue LoadError
    # No future version of the adapter, or the adapter was already a future
    # one. Keep going as usual...
    spec
  end
end