Sha256: 183e38cac4f8c3748734b5c9cf7722aad5da4407e817ac9f626a40d7693ee94f

Contents?: true

Size: 1.45 KB

Versions: 13

Compression:

Stored size: 1.45 KB

Contents

require "array_enumerator"
require "auto_autoloader"
require "datet"
require "simple_delegate"
require "string-cases"
require "wref"

class Baza
  AutoAutoloader.autoload_sub_classes(self, __FILE__)

  class << self
    attr_writer :default_db
  end

  def self.default_db
    unless @default_db
      config_file = "#{Dir.pwd}/config/baza_database.rb"
      init_file = "#{Dir.pwd}/config/initializers/baza_database.rb"

      begin
        load(config_file)
      rescue LoadError
        load(init_file)
      end

      unless @default_db.is_a?(Baza::Db)
        raise "Config file didn't return a Baza::Db: #{@default_db.class.name}"
      end
    end

    @default_db
  end

  def self.drivers
    Enumerator.new do |yielder|
      Dir.foreach("#{File.dirname(__FILE__)}/baza/driver") do |file|
        if (match = file.match(/\A(.+?)\.rb\Z/))
          load_driver(match[1])

          driver_name = StringCases.snake_to_camel(match[1])
          yielder << {
            class: Baza::Driver.const_get(driver_name),
            snake_name: match[1],
            camel_name: driver_name
          }
        end
      end
    end
  end

  def self.load_driver(name)
    require_relative "baza/driver/#{name}"

    loads = %w(databases database tables table columns column indexes index result commands)
    loads.each do |load|
      file_path = "#{File.dirname(__FILE__)}/baza/driver/#{name}/#{load}"
      require_relative file_path if File.exist?(file_path)
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
baza-0.0.33 lib/baza.rb
baza-0.0.32 lib/baza.rb
baza-0.0.31 lib/baza.rb
baza-0.0.30 lib/baza.rb
baza-0.0.29 lib/baza.rb
baza-0.0.28 lib/baza.rb
baza-0.0.27 lib/baza.rb
baza-0.0.26 lib/baza.rb
baza-0.0.25 lib/baza.rb
baza-0.0.24 lib/baza.rb
baza-0.0.23 lib/baza.rb
baza-0.0.22 lib/baza.rb
baza-0.0.21 lib/baza.rb