Module: Statusbot::Models

Defined in:
lib/statusbot/models.rb,
lib/statusbot/models/version.rb

Defined Under Namespace

Classes: MissingConfigurationError

Constant Summary collapse

VERSION =
"0.6.0"

Class Method Summary collapse

Class Method Details

.connect(configuration = 'db/config.yml', load_models = true) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/statusbot/models.rb', line 16

def self.connect(configuration='db/config.yml', load_models=true)
  environment = ENV['RAILS_ENV'] || 'development'
  project_root = File.dirname(File.absolute_path(__FILE__))

  unless File.exist?(configuration)
    raise MissingConfigurationError.new("could not find '#{configuration}'")
  end

  if load_models
    Dir.glob(File.expand_path(project_root + "/../../app/models") + "/*.rb").each{ |f| require f }
  end


  connection_details = YAML::load(File.open(configuration))
  ActiveRecord::Base.establish_connection(connection_details[environment])
end