Skip to content

Commit

Permalink
config
Browse files Browse the repository at this point in the history
  • Loading branch information
NOX73 committed Aug 4, 2012
1 parent d8bdae4 commit 2e07da8
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
20 changes: 18 additions & 2 deletions bin/mail_sandbox
@@ -1,11 +1,27 @@
#!/usr/bin/env ruby
require 'mail_sandbox'
require "eventmachine"
require 'optparse'
require 'fileutils'

MailSandbox.subscribe MailSandbox::Observer::Http.new('http://192.168.30.45:8080/api/mail_messages')
config = MailSandbox::Config.new

OptionParser.new do |opts|

opts.on("-c", "--config-file FILE", "Config file") do |f|
config.config_file = f
end

end.parse!

config.load_from_yml_file if config.config_file

if config.http_observe?
MailSandbox.subscribe MailSandbox::Observer::Http.new(config.http_observe_url)
end

EventMachine::run {
EventMachine::start_server '127.0.0.1', 2525, MailSandbox::Server
EventMachine::start_server config.listen, config.port, MailSandbox::Server
}


1 change: 1 addition & 0 deletions lib/mail_sandbox.rb
Expand Up @@ -6,6 +6,7 @@ module MailSandbox
autoload :Message, 'mail_sandbox/message'
autoload :Observer, 'mail_sandbox/observer'
autoload :Subscribe, 'mail_sandbox/subscribe'
autoload :Config, 'mail_sandbox/config'

def self.subscribe(observer)
Subscribe.subscribe observer
Expand Down
30 changes: 30 additions & 0 deletions lib/mail_sandbox/config.rb
@@ -0,0 +1,30 @@
module MailSandbox
class Config

def initialize
@config = {
:listen => '127.0.0.1',
:port => 2525
}
end

def load_from_yml_file
yaml = YAML.load_file config_file

yaml.each do |key, val|
self.send "#{key}=", val
end
end

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

end
end

0 comments on commit 2e07da8

Please sign in to comment.