class Tableflip::DatabaseHandle

Constants

DATABASE_CONFIG_FILE

Constants ============================================================

DEFAULT_OPTIONS
PARAM_MAP

Public Class Methods

config() click to toggle source
# File lib/tableflip/database_handle.rb, line 39
def self.config
  @config ||= begin
    _config_path = self.config_path

    if (!_config_path)
      STDERR.puts("Could not find #{DATABASE_CONFIG_FILE}")
      exit(-1)
    elsif (File.exists?(_config_path))
      File.open(_config_path) do |f|
        YAML.load(f)
      end
    else
      STDERR.puts "Could not open #{_config_path}"
      exit(-1)
    end
  end
end
config_path() click to toggle source

Class Methods ========================================================

# File lib/tableflip/database_handle.rb, line 21
def self.config_path
  path = Dir.pwd
  last_path = nil

  while (path != last_path)
    config_path = File.expand_path("config/#{DATABASE_CONFIG_FILE}", path)

    if (File.exist?(config_path))
      return config_path
    end

    last_path = path
    path = File.expand_path('..', path)
  end

  nil
end
connect(env, options) click to toggle source
# File lib/tableflip/database_handle.rb, line 79
def self.connect(env, options)
  Mysql2::EM::Client.new(self.environment_config(env).merge(options))
end
environment_config(env) click to toggle source
# File lib/tableflip/database_handle.rb, line 61
def self.environment_config(env)
  _config = self.config[env]

  unless (_config)
    raise "No environment #{env} defined in #{self.config_path}"
  end

  options = DEFAULT_OPTIONS.dup

  _config.each do |k, v|
    options[PARAM_MAP[k]] = v
  end

  options[:loggers] = [ ]

  options
end
runtime_environment() click to toggle source
# File lib/tableflip/database_handle.rb, line 57
def self.runtime_environment
  DAEMON_ENV or 'development'
end