Class: Blurrily::Server
- Inherits:
-
Object
- Object
- Blurrily::Server
- Defined in:
- lib/blurrily/server.rb
Defined Under Namespace
Modules: Handler
Instance Method Summary collapse
-
#initialize(options) ⇒ Server
constructor
A new instance of Server.
- #start ⇒ Object
Constructor Details
#initialize(options) ⇒ Server
Returns a new instance of Server.
9 10 11 12 13 14 15 16 |
# File 'lib/blurrily/server.rb', line 9 def initialize() @host = .fetch(:host, '0.0.0.0') @port = .fetch(:port, Blurrily::DEFAULT_PORT) directory = .fetch(:directory, Dir.pwd) @map_group = MapGroup.new(directory) @command_processor = CommandProcessor.new(@map_group) end |
Instance Method Details
#start ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/blurrily/server.rb', line 18 def start EventMachine.run do # hit Control + C to stop Signal.trap("INT") { EventMachine.stop } Signal.trap("TERM") { EventMachine.stop } saver = proc { @map_group.save } EventMachine.add_periodic_timer(60, &saver) EventMachine.add_shutdown_hook(&saver) Signal.trap("USR1", &saver) EventMachine.start_server(@host, @port, Handler, @command_processor) end end |