-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.rb
66 lines (55 loc) · 1.19 KB
/
config.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
58
59
60
61
62
63
64
65
66
module App
class Conf
@default = {}
@dev = {}
@prod = {}
def self.default(opts=nil)
opts.nil? ? @default : @default.deep_merge!(opts)
end
def self.dev(opts=nil)
opts.nil? ? @dev : @dev.deep_merge!(opts)
end
def self.prod(opts=nil)
opts.nil? ? @prod : @prod.deep_merge!(opts)
end
end
end
class Neo::ConfigFiles
@config_files =
%W(#{Neo.app_dir}/config/*.rb #{Neo.app_dir}/modules/*/config/*.rb).reduce([]) {|memo, dir|
Dir[dir].each do |file|
memo << file
end
memo
}
def self.get
@config_files
end
def self.remove(file)
@config_files.delete_if {|conf_file| file == conf_file}
end
end
module Neo
module Config
attr_accessor :main
def initialize
config_files = Neo::ConfigFiles.get
config_files.each do |file|
require file
Neo::ConfigFiles.remove file
end
env_var = App::Conf.default[:env]
env = App::Conf.send(env_var)
Neo::Params.env = env_var
@main = App::Conf.default
@main.deep_merge!(env)
end
def [](key)
@main[key]
end
def []=(key,value)
@main[key] = value
end
make_modular
end
end