Sha256: 300bf68254158015def6186029f1620e5551dfde86466eebf6dce0c5649f3da9

Contents?: true

Size: 736 Bytes

Versions: 3

Compression:

Stored size: 736 Bytes

Contents

require 'active_record/connection_adapters/connection_specification'

module ActiveReplicas
  module Rails4
    module Helpers
      extend self

      # Returns an instance of `ActiveRecord::ConnectionAdapters::ConnectionPool`
      # configured with the given specification.
      def self.connection_pool_for_spec(config_spec)
        @@resolver ||= ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new({})

        # Turns a hash configuration into a `ConnectionSpecification` that can
        # be passed to a `ConnectionPool`.
        spec = @@resolver.spec ActiveSupport::HashWithIndifferentAccess.new(config_spec)

        ActiveRecord::ConnectionAdapters::ConnectionPool.new spec
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
active_replicas-0.5.1 lib/active_replicas/rails4/helpers.rb
active_replicas-0.5.0 lib/active_replicas/rails4/helpers.rb
active_replicas-0.4.0 lib/active_replicas/rails4/helpers.rb