forked from shokai/sinatra-heroku-phantomjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.rb
66 lines (55 loc) · 1.01 KB
/
bootstrap.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
require 'yaml'
class Bootstrap
def self.default
[]
end
def self.init(*inits)
[default, inits].flatten.uniq.each do |cat|
Dir.glob("#{File.dirname(__FILE__)}/#{cat}/*.rb").each do |rb|
puts "load #{rb}"
require rb
end
end
end
end
class Conf
def self.[](key)
ENV[key] || conf[key]
end
def self.[]=(key,value)
conf[key] = value
end
def self.file
@@file ||= File.dirname(__FILE__)+'/config.yml'
end
def self.file=(name)
@@file = name
end
def self.conf
begin
@@conf ||= YAML::load self.open.read
rescue => e
STDERR.puts e
STDERR.puts "config.yml load error!!"
exit 1
end
end
def self.open(opt=nil, &block)
if block_given?
yield File.open(self.file, opt)
else
return File.open(self.file, opt)
end
end
def self.save
self.open 'w+' do |f|
f.write self.to_yaml
end
end
def self.to_yaml
self.conf.to_yaml
end
def self.to_json
self.conf.to_json
end
end