Sha256: 11a38b5e4fed5cfc89eff28cb1d412ca02e1daeb01c8e23d77fefa259d94a549

Contents?: true

Size: 719 Bytes

Versions: 9

Compression:

Stored size: 719 Bytes

Contents

require 'active_support/core_ext/hash/keys'

module FreshConnection
  class ConnectionFactory
    def initialize(group, modify_spec = {})
      @group = group.to_sym
      @modify_spec = modify_spec.symbolize_keys
    end

    def new_connection
      ActiveRecord::Base.__send__(adapter_method, spec)
    end

    private

    def adapter_method
      @adapter_method ||= ar_spec.adapter_method
    end

    def spec
      @spec ||= build_spec
    end

    def build_spec
      config = ar_spec.config.symbolize_keys
      group_config = (config[@group] || {}).symbolize_keys
      config.merge(group_config).merge(@modify_spec)
    end

    def ar_spec
      ActiveRecord::Base.connection_pool.spec
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
fresh_connection-2.2.0 lib/fresh_connection/connection_factory.rb
fresh_connection-2.1.2 lib/fresh_connection/connection_factory.rb
fresh_connection-2.1.1 lib/fresh_connection/connection_factory.rb
fresh_connection-2.1.0 lib/fresh_connection/connection_factory.rb
fresh_connection-2.0.4 lib/fresh_connection/connection_factory.rb
fresh_connection-2.0.3 lib/fresh_connection/connection_factory.rb
fresh_connection-0.4.4 lib/fresh_connection/connection_factory.rb
fresh_connection-1.0.1 lib/fresh_connection/connection_factory.rb
fresh_connection-2.0.2 lib/fresh_connection/connection_factory.rb