Class: Notes::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/notes-cli/server.rb

Constant Summary collapse

SERVER_DEFAULTS =
{
  :Host => '127.0.0.1',
  :Port => '9292'
}

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Server

Returns a new instance of Server.



12
13
14
# File 'lib/notes-cli/server.rb', line 12

def initialize(argv)
  @options = SERVER_DEFAULTS.merge(parse_options(argv))
end

Instance Method Details

#parse_options(args) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/notes-cli/server.rb', line 16

def parse_options(args)
  options = {}
  OptionParser.new do |opts|
    opts.on('-p', '--port [PORT]', 'The port to run on') do |port|
      options[:Port] = port
    end
  end.parse!(args)

  options
end

#startObject



27
28
29
30
31
# File 'lib/notes-cli/server.rb', line 27

def start
  Rack::Handler::WEBrick.run(Notes::Web, @options) do |server|
      [:INT, :TERM].each { |sig| trap(sig) { server.stop } }
  end
end