class WSOC::Runner

Attributes

host[R]

Host to run the WSOC server on

port[R]

Port to run the WSOC server on

Public Class Methods

new() click to toggle source

Creates a new runner.

@since 0.1.0

# File lib/wsoc/runner.rb, line 40
def initialize
  @host = Config::DEFAULT_HOST
  @port = Config::DEFAULT_PORT
  @handler = nil
end
start(args=ARGV) click to toggle source

Starts the runner.

@param [Array<String>] argvs (ARGV)

The arguments to run the runner with.

@since 0.1.0

# File lib/wsoc/runner.rb, line 54
def Runner.start(args=ARGV)
  runner = self.new()
  runner.run(*args)
end

Public Instance Methods

run(*args) click to toggle source

Runs the runner.

@param [Array<String>] args

The arguments to run the runner with.

@since 0.1.0

# 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

Protected Instance Methods

optparse(*args) click to toggle source

Parses the given arguments.

@param [Array<String>] args

The arguments to parse.

@since 0.1.0

# 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