module RestGW2::Runner
Public Instance Methods
config_ru_path()
click to toggle source
# File lib/rest-gw2/server/runner.rb, line 22 def config_ru_path "#{root}/config.ru" end
help()
click to toggle source
# File lib/rest-gw2/server/runner.rb, line 96 def help optt = options.transpose maxn = optt.first.map(&:size).max maxd = optt.last .map(&:size).max "Usage: rest-gw2 [OPTIONS]\n" + options.map{ |(name, desc)| if name.end_with?(':') name else sprintf(" %-*s %-*s", maxn, name, maxd, desc) end }.join("\n") end
load_rack()
click to toggle source
# File lib/rest-gw2/server/runner.rb, line 83 def load_rack require 'rack' rescue LoadError => e warn(e) puts "Maybe you should install rack by running: gem install rack" exit(1) end
load_rack_handlers()
click to toggle source
# File lib/rest-gw2/server/runner.rb, line 91 def load_rack_handlers require 'rack-handlers' rescue LoadError end
missing_arg(arg)
click to toggle source
# File lib/rest-gw2/server/runner.rb, line 78 def missing_arg arg warn("Missing argument: #{arg}") exit(1) end
options()
click to toggle source
# File lib/rest-gw2/server/runner.rb, line 7 def options @options ||= [['Options:' , '' ], ['-o, --host HOST' , 'Use HOST (default: 0.0.0.0)' ], ['-p, --port PORT' , 'Use PORT (default: 8080)' ], ['-s, --server SERVER', 'Use SERVER (default: webrick)'], ['-c, --configru' , 'Print where the config.ru is' ], ['-h, --help' , 'Print this message' ], ['-v, --version' , 'Print the version' ]] end
parse(argv)
click to toggle source
# File lib/rest-gw2/server/runner.rb, line 37 def parse argv unused, host, port, server = [], '0.0.0.0', 8080, nil until argv.empty? case arg = argv.shift when /^-o=?(.+)?/, /^--host=?(.+)?/ host = $1 || argv.shift missing_arg('host') unless host when /^-p=?(.+)?/, /^--port=?(.+)?/ port = $1 || argv.shift missing_arg('port') unless port when /^-s=?(.+)?/, /^--server=?(.+)?/ server = $1 || argv.shift missing_arg('server') unless server when /^-c/, '--configru' puts(config_ru_path) exit when /^-h/, '--help' puts(help) exit when /^-v/, '--version' require 'rest-gw2/version' puts(RestGW2::VERSION) exit else unused << arg end end [unused, host, port, server] end
parse_next(argv, arg)
click to toggle source
# File lib/rest-gw2/server/runner.rb, line 74 def parse_next argv, arg argv.unshift("-#{arg[2..-1]}") if arg.size > 2 end
root()
click to toggle source
# File lib/rest-gw2/server/runner.rb, line 18 def root File.expand_path("#{__dir__}/../../../") end
run(argv=ARGV)
click to toggle source
# File lib/rest-gw2/server/runner.rb, line 26 def run argv=ARGV unused, host, port, server = parse(argv) warn("Unused arguments: #{unused.inspect}") unless unused.empty? load_rack load_rack_handlers handler = server && Rack::Handler.get(server) || Rack::Handler.default handler.run(Rack::Builder.new{ eval(File.read(RestGW2::Runner.config_ru_path)) }.to_app, :Host => host, :Port => port, :config => root) end