Sha256: bd4f0d60cc111f17ee018841de48ad75dd35efb8569c17a6093b6b42ebe5967b

Contents?: true

Size: 714 Bytes

Versions: 4

Compression:

Stored size: 714 Bytes

Contents

require 'pathname'
require 'fileutils'
require 'ardb'
require 'ardb/adapter/base'

class Ardb::Adapter

  class Sqlite < Base

    def db_file_path
      if (path = Pathname.new(self.database)).absolute?
        path.to_s
      else
        Ardb.config.root_path.join(path).to_s
      end
    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.config_settings)
    end

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

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ardb-0.27.3 lib/ardb/adapter/sqlite.rb
ardb-0.27.2 lib/ardb/adapter/sqlite.rb
ardb-0.27.1 lib/ardb/adapter/sqlite.rb
ardb-0.27.0 lib/ardb/adapter/sqlite.rb