Class: Ruku::Clients::Web

Inherits:
Object
  • Object
show all
Defined in:
lib/ruku/clients/web.rb

Defined Under Namespace

Classes: AjaxServlet

Constant Summary collapse

DEFAULT_PORT =
3030

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Web

Returns a new instance of Web.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ruku/clients/web.rb', line 15

def initialize(opts={})
  @options = OpenStruct.new(opts)
  handle_options

  if options.install
    require File.join(File.dirname(__FILE__), 'web', 'installer')
    WebInstaller.install(options.port || DEFAULT_PORT)
    exit
  end

  server_options = {
    :Port => options.port || DEFAULT_PORT,
    :DocumentRoot => File.join(File.dirname(__FILE__), 'web', 'static')
  }
  @server = HTTPServer.new(server_options)

  ['INT', 'TERM'].each do |signal|
    trap(signal) { @server.shutdown }
  end

  @server.mount("/ajax", AjaxServlet)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



13
14
15
# File 'lib/ruku/clients/web.rb', line 13

def options
  @options
end

Instance Method Details

#handle_optionsObject

Parse and handle command line options



43
44
45
46
47
48
49
# File 'lib/ruku/clients/web.rb', line 43

def handle_options
  OptionParser.new do |opts|
    opts.on('-p', '--port PORT') {|p| options.port = p.to_i }
    opts.on('--install') { options.install = true }
    opts.on('--web') { } # ignore
  end.parse!
end

#startObject



38
39
40
# File 'lib/ruku/clients/web.rb', line 38

def start
  @server.start
end