Sha256: 6c4e224e5bb51c1d3b8ea390ea511fed79a49d9435c8ab314ed5be138f0e46fd

Contents?: true

Size: 1021 Bytes

Versions: 3

Compression:

Stored size: 1021 Bytes

Contents

class Atomically::AdapterCheckService
  def initialize(klass)
    @klass = klass
  end

  def pg?
    possible_pg_klasses.any?{|s| @klass.connection.is_a?(s) }
  end

  def mysql?
    possible_mysql_klasses.any?{|s| @klass.connection.is_a?(s) }
  end

  private

  def possible_pg_klasses
    @possible_pg_klasses ||= [].tap do |result|
      result << ActiveRecord::ConnectionAdapters::PostgreSQLAdapter if defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
      result << ActiveRecord::ConnectionAdapters::MakaraPostgreSQLAdapter if defined?(ActiveRecord::ConnectionAdapters::MakaraPostgreSQLAdapter)
    end
  end

  def possible_mysql_klasses
    @possible_mysql_klasses ||= [].tap do |result|
      result << ActiveRecord::ConnectionAdapters::Mysql2Adapter if defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter)
      result << ActiveRecord::ConnectionAdapters::MakaraMysql2Adapter if defined?(ActiveRecord::ConnectionAdapters::MakaraMysql2Adapter)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
atomically-1.1.5 lib/atomically/adapter_check_service.rb
atomically-1.1.4 lib/atomically/adapter_check_service.rb
atomically-1.1.3 lib/atomically/adapter_check_service.rb