Sha256: c0d42de73bbb10816d124cb5ae42974467258b0d5ac98dbac74b8f09e2ed87ce

Contents?: true

Size: 841 Bytes

Versions: 12

Compression:

Stored size: 841 Bytes

Contents

module DbCharmer
  module ConnectionSwitch
    module ClassMethods
      def coerce_to_connection_proxy(conn, should_exist = true)
        return nil if conn.nil?

        if conn.kind_of?(Symbol) || conn.kind_of?(String)
          return DbCharmer::ConnectionFactory.connect(conn, should_exist)
        end

        if conn.respond_to?(:db_charmer_connection_proxy)
          return conn.db_charmer_connection_proxy
        end

        if conn.kind_of?(ActiveRecord::ConnectionAdapters::AbstractAdapter)
          return conn
        end

        raise "Unsupported connection type: #{conn.class}"
      end

      def switch_connection_to(conn, require_config_to_exist = true)
        self.db_charmer_connection_proxy = coerce_to_connection_proxy(conn, require_config_to_exist)
        self.hijack_connection!
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
db-charmer-1.5.5 lib/db_charmer/connection_switch.rb
db-charmer-1.5.4 lib/db_charmer/connection_switch.rb
db-charmer-1.5.3 lib/db_charmer/connection_switch.rb
db-charmer-1.5.2 lib/db_charmer/connection_switch.rb
db-charmer-1.5.1 lib/db_charmer/connection_switch.rb
db-charmer-1.5.0 lib/db_charmer/connection_switch.rb
db-charmer-1.4.6 lib/db_charmer/connection_switch.rb
db-charmer-1.4.5 lib/db_charmer/connection_switch.rb
db-charmer-1.4.4 lib/db_charmer/connection_switch.rb
db-charmer-1.4.3 lib/db_charmer/connection_switch.rb
db-charmer-1.4.1 lib/db_charmer/connection_switch.rb
db-charmer-1.4.0 lib/db_charmer/connection_switch.rb