Sha256: a4db94a15c70db1b14b3edff0185682466460e49c82340a363bfb275f68183d9

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

class Combustion::Database::Reset
  UnsupportedDatabase = Class.new StandardError

  def self.call(adapter = nil)
    new(adapter).call
  end

  def initialize(adapter = nil)
    @adapter = adapter

    set_configurations
  end

  def call
    operator.reset
  end

  private

  def configuration
    @configuration ||= ActiveRecord::Base.configurations['test']
  end

  def operator
    operator_class.new configuration
  end

  def operator_class
    @operator ||= case configuration['adapter']
    when /mysql/
      Combustion::Databases::MySQL
    when /postgresql/, /postgis/
      Combustion::Databases::PostgreSQL
    when /sqlite/
      Combustion::Databases::SQLite
    when /sqlserver/
      Combustion::Databases::SQLServer
    when 'oci', 'oracle'
      Combustion::Databases::Oracle
    when 'firebird'
      Combustion::Databases::Firebird
    else
      raise UnsupportedDatabase,
        "Unsupported database type: #{configuration['adapter']}"
    end
  end

  def set_configurations
    ActiveRecord::Base.configurations = YAML.load(
      ERB.new(File.read("#{Rails.root}/config/database.yml")).result
    )
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
combustion-0.5.5 lib/combustion/database/reset.rb