Class: WSOC::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/wsoc/runner.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRunner

Creates a new runner.

Since:

  • 0.1.0



40
41
42
43
44
# File 'lib/wsoc/runner.rb', line 40

def initialize
  @host = Config::DEFAULT_HOST
  @port = Config::DEFAULT_PORT
  @handler = nil
end

Instance Attribute Details

#hostObject (readonly)

Host to run the WSOC server on



30
31
32
# File 'lib/wsoc/runner.rb', line 30

def host
  @host
end

#portObject (readonly)

Port to run the WSOC server on



33
34
35
# File 'lib/wsoc/runner.rb', line 33

def port
  @port
end

Class Method Details

.start(args = ARGV) ⇒ Object

Starts the runner.

Parameters:

  • argvs (Array<String>)

    (ARGV) The arguments to run the runner with.

Since:

  • 0.1.0



54
55
56
57
# File 'lib/wsoc/runner.rb', line 54

def Runner.start(args=ARGV)
  runner = self.new()
  runner.run(*args)
end

Instance Method Details

#optparse(*args) ⇒ Object (protected)

Parses the given arguments.

Parameters:

  • args (Array<String>)

    The arguments to parse.

Since:

  • 0.1.0



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/wsoc/runner.rb', line 91

def optparse(*args)
  opts = OptionParser.new

  opts.banner = "usage: #{$0} [options]"

  opts.on('-H','--host HOST',"The host to run the server on","Default: #{@host}") do |host|
    @host = host
  end

  opts.on('-p','--port PORT',"The port to run the server on","Default: #{@port}") do |port|
    @port = port.to_i
  end

  opts.on('--s','--server NAME','Rack handler to run the server under') do |handler|
    @handler = handler
  end

  opts.on('-h','--help','Display the help output') do
    puts opts
    exit
  end

  begin
    opts.parse!(args)
  rescue OptionParser::InvalidOption => e
    STDERR.puts e.message
    STDERR.puts opts
    exit -1
  end
end

#run(*args) ⇒ Object

Runs the runner.

Parameters:

  • args (Array<String>)

    The arguments to run the runner with.

Since:

  • 0.1.0



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/wsoc/runner.rb', line 67

def run(*args)
  optparse(*args)

  options = {
    :env => :production,
    :host => @host,
    :port => @port
  }

  options.merge!(:server => @handler) if @handler

  App.run!(options)
end