Sha256: f3d73855c33325f95ea84ff617e0c63257907b0b497a0d740e372d75745445f7

Contents?: true

Size: 593 Bytes

Versions: 7

Compression:

Stored size: 593 Bytes

Contents

module FreshConnection
  class ConnectionFactory
    def initialize(group, modify_spec = {})
      @group = group.to_sym
      @modify_spec = modify_spec
    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
      config.merge(config[@group] || {}).merge(@modify_spec)
    end

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
fresh_connection-2.0.1 lib/fresh_connection/connection_factory.rb
fresh_connection-2.0.0 lib/fresh_connection/connection_factory.rb
fresh_connection-1.0.0 lib/fresh_connection/connection_factory.rb
fresh_connection-0.4.3 lib/fresh_connection/connection_factory.rb
fresh_connection-0.4.2 lib/fresh_connection/connection_factory.rb
fresh_connection-0.4.1 lib/fresh_connection/connection_factory.rb
fresh_connection-0.4.0 lib/fresh_connection/connection_factory.rb