Sha256: cbe89c2c30d63e274fcbeb326b6aef018579873ebcba731866b4e7a93868e670

Contents?: true

Size: 624 Bytes

Versions: 2

Compression:

Stored size: 624 Bytes

Contents

require "fileutils"
require "ardb"
require "ardb/adapter/base"

module Ardb::Adapter
  class Sqlite < Ardb::Adapter::Base
    def db_file_path
      File.expand_path(self.database, self.config.root_path)
    end

    def validate!
      if File.exist?(self.db_file_path)
        raise RuntimeError, "`#{self.database}` already exists"
      end
    end

    def create_db
      validate!
      FileUtils.mkdir_p File.dirname(self.db_file_path)
      ActiveRecord::Base.establish_connection(self.connect_hash)
    end

    def drop_db
      FileUtils.rm(self.db_file_path) if File.exist?(self.db_file_path)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ardb-0.29.1 lib/ardb/adapter/sqlite.rb
ardb-0.29.0 lib/ardb/adapter/sqlite.rb