Class: MailSandbox::Config
- Inherits:
-
Object
- Object
- MailSandbox::Config
show all
- Defined in:
- lib/mail_sandbox/config.rb
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Config
@config:Array
:listen:String
:port:Integer
:log_level:Symbol = :info (:info :error :warn :debug)
:server_params:Array
:auth:Boolean - enable smtp authorization, now it's only PLAIN
:config_file:String - path to yaml config file
:http_observe?:Boolean - subscribe Observer::Http to receive new messages and push them by http protocol
:http_observe_url:String - url for push on receive new messages, use by Observer::Http
:daemonize:Bool - run daemonized in the background
:pidfile:String - PATH to pid file
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/mail_sandbox/config.rb', line 16
def initialize
@config = {
:listen => '127.0.0.1',
:port => 2525,
:log_level => :info,
:server_params => {
:auth => true
}
}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, val = nil) ⇒ Object
48
49
50
51
52
53
54
55
56
|
# File 'lib/mail_sandbox/config.rb', line 48
def method_missing(method, val = nil)
m = method.to_s
if m =~ /=$/
key = m.match(/(.*)=$/)[1]
@config[key.to_sym] = val
else
@config[method]
end
end
|
Instance Method Details
#load_from_yml_file(env, file = nil) ⇒ Object
27
28
29
30
31
32
|
# File 'lib/mail_sandbox/config.rb', line 27
def load_from_yml_file(env, file = nil)
file ||= config_file
yaml = YAML.load_file(file)[env.to_s]
merge_config(yaml)
end
|
#merge_config(hash) ⇒ Object
34
35
36
|
# File 'lib/mail_sandbox/config.rb', line 34
def merge_config(hash)
symbolize_merge(@config, hash)
end
|
#symbolize_merge(conf, hash) ⇒ Object
38
39
40
41
42
43
44
45
46
|
# File 'lib/mail_sandbox/config.rb', line 38
def symbolize_merge(conf, hash)
hash.each do |key, val|
if val.kind_of? Hash
symbolize_merge(conf[key.to_sym], val)
else
conf[key.to_sym] = val
end
end
end
|