-
Notifications
You must be signed in to change notification settings - Fork 3
/
environment.rb
57 lines (45 loc) · 1.17 KB
/
environment.rb
1
2
3
4
5
6
7
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
require 'bundler'
ENV['RACK_ENV'] ||= 'development'
Bundler.require(:default, (ENV['RACK_ENV'].downcase.intern))
$: << File.dirname(__FILE__)
class Environment
def self.reload!
[:models, :lib].each do |dir|
Dir[File.join(dir.to_s, '*')].each do |file|
send(ENV['RACK_ENV'] == 'development' ? :load : :require, file) unless File.directory? file
end
end
Dir[File.join('config', '*.yml')].each do |yaml_file|
Config.set(File.basename(yaml_file).sub(/\.yml$/,'').intern,YAML.load(File.read(yaml_file)))
end
ActiveRecord::Base.establish_connection Config.database[ENV['RACK_ENV'].downcase.underscore]
end
module Config
class << self
def set(key, value)
@store ||= {}
@store[key.to_sym] = value
end
def get(key)
@store[key.to_sym]
end
def [](key)
get(key)
end
def []=(key, value)
set(key, value)
end
def method_missing(key)
get(key)
end
end
end
end
Environment.reload!
configure :development do
before do
Environment.reload!
end
end
helpers TeamFun::Helpers
set :root, File.dirname(__FILE__)