Sha256: d9313f044b2c901e1aa5d5cd39077c22d09da865daa3208fbe40cc634eaea50a

Contents?: true

Size: 949 Bytes

Versions: 18

Compression:

Stored size: 949 Bytes

Contents

require 'active_support'
require 'active_support/deprecation'
require 'active_record/connection_adapters/nulldb_adapter'

module NullDB
  class Configuration < Struct.new(:project_root); end

  class << self
    def configure
      @configuration = Configuration.new.tap {|c| yield c}
    end

    def configuration
      if @configuration.nil?
        raise "NullDB not configured. Require a framework, ex 'nulldb/rails'"
      end

      @configuration
    end

    def nullify(options={})
      begin
        @prev_connection = ActiveRecord::Base.connection_pool.try(:spec)
      rescue ActiveRecord::ConnectionNotEstablished
      end
      ActiveRecord::Base.establish_connection(options.merge(:adapter => :nulldb))
    end

    def restore
      if @prev_connection
        ActiveRecord::Base.establish_connection(@prev_connection.config)
      end
    end

    def checkpoint
      ActiveRecord::Base.connection.checkpoint!
    end
  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
activerecord-nulldb-adapter-1.1.1 lib/nulldb/core.rb
activerecord-nulldb-adapter-1.1.0 lib/nulldb/core.rb
activerecord-nulldb-adapter-1.0.1 lib/nulldb/core.rb
activerecord-nulldb-adapter-1.0.0 lib/nulldb/core.rb
activerecord-nulldb-adapter-0.9.0 lib/nulldb/core.rb
activerecord-nulldb-adapter-0.8.0 lib/nulldb/core.rb
activerecord-nulldb-adapter-0.7.0 lib/nulldb/core.rb
activerecord-nulldb-adapter-0.6.0 lib/nulldb/core.rb
activerecord-nulldb-adapter-0.3.8 lib/nulldb/core.rb
nulldb-0.3.7.pre.alpha.1 lib/nulldb/core.rb
activerecord-nulldb-adapter-0.3.7 lib/nulldb/core.rb
activerecord-nulldb-adapter-0.3.6 lib/nulldb/core.rb
activerecord-nulldb-adapter-0.3.5 lib/nulldb/core.rb
activerecord-nulldb-adapter-0.3.4 lib/nulldb/core.rb
activerecord-nulldb-adapter-0.3.3 lib/nulldb/core.rb
activerecord-nulldb-adapter-0.3.2 lib/nulldb/core.rb
activerecord-nulldb-adapter-0.3.1 lib/nulldb/core.rb
activerecord-nulldb-adapter-0.3.0 lib/nulldb/core.rb