Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
49 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |