Sha256: a2982af8f921dea58c9fb6282c18e1b0dcfbeaa9fea8cc2f03897f6714fee9bd

Contents?: true

Size: 695 Bytes

Versions: 1

Compression:

Stored size: 695 Bytes

Contents

require "string-cases"

class Baza
  #Autoloader for subclasses.
  def self.const_missing(name)
    file_name = name.to_s.gsub(/(.)([A-Z])/,'\1_\2').downcase
    require "#{File.dirname(__FILE__)}/../include/#{file_name}.rb"
    raise "Still not defined: '#{name}'." unless Baza.const_defined?(name)
    return Baza.const_get(name)
  end

  def self.default_db=(db)
    @default_db = db
  end

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

      load(config_file)

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

    return @default_db
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
baza-0.0.16 lib/baza.rb