Class: Rambo::Env

Inherits:
Object
  • Object
show all
Defined in:
lib/rambo/env.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEnv

Returns a new instance of Env.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rambo/env.rb', line 8

def initialize
  begin
    # TODO: config reload
  
    if dbconf = Env.config['datamapper']
      require 'dm-core'
      require 'dm-validations'
      require 'dm-timestamps'
      #DataMapper.setup(:default, 'mysql://localhost/moo_development')
      @@connection ||= DataMapper.setup(
        :default,
        :adapter => :mysql, 
        :host => dbconf['host'], 
        :database => dbconf['database'], 
        :username => dbconf['username'], 
        :password => dbconf['password']
      )
      @@dblogger ||= DataObjects::Mysql.logger = DataObjects::Logger.new(STDOUT, dbconf['logging']) if dbconf['logging']
    end
  rescue Exception => e
    puts "Exception initializing environment: #{e.message}"
    puts e.backtrace.join("\n")
  end
  
  Dir["controller/*.rb"].each { |x| funkyload x }
  Dir["model/*.rb"].each { |x| funkyload x }
  Dir["lib/*.rb"].each { |x| funkyload x }
  Dir["*.rb"].each { |x| funkyload x unless x == 'Rakefile.rb' }
end

Class Method Details

.configObject



3
4
5
6
# File 'lib/rambo/env.rb', line 3

def self.config
  @@config ||= YAML.load_file("config.yml") rescue nil
  @@config ||= {}
end