Sha256: 4c10dc664f34a5193396d366c1b9e42493794fda6176f9e69d160eff8e1b8909

Contents?: true

Size: 991 Bytes

Versions: 2

Compression:

Stored size: 991 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

2 entries across 2 versions & 1 rubygems

Version Path
atomically-1.1.2 lib/atomically/adapter_check_service.rb
atomically-1.1.1 lib/atomically/adapter_check_service.rb