Class: GRI::WMain
Instance Attribute Summary collapse
-
#app ⇒ Object
writeonly
Sets the attribute app.
Instance Method Summary collapse
-
#initialize(app = nil) ⇒ WMain
constructor
A new instance of WMain.
- #optparse(opts) ⇒ Object
- #run(opts = nil) ⇒ Object
Constructor Details
#initialize(app = nil) ⇒ WMain
Returns a new instance of WMain.
12 13 14 15 16 |
# File 'lib/gri/wmain.rb', line 12 def initialize app=nil @app = app config_path = ENV['GRI_CONFIG_PATH'] || Config::DEFAULT_PATH Config.init config_path end |
Instance Attribute Details
#app=(value) ⇒ Object (writeonly)
Sets the attribute app
10 11 12 |
# File 'lib/gri/wmain.rb', line 10 def app=(value) @app = value end |
Instance Method Details
#optparse(opts) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/gri/wmain.rb', line 43 def optparse opts op = OptionParser.new op.on('--debug') {$debug = true; STDOUT.sync = true} op.on('-d', '--daemonize') {opts[:daemonize] = true} op.on('-h', '--host HOST') {|arg| opts[:Host] = arg} op.on('-p', '--port PORT', Integer) {|arg| opts[:Port] = arg} op.on('-s', '--server SERVER') {|arg| opts[:server] = arg} class <<op attr_accessor :options end op. = opts op end |
#run(opts = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/gri/wmain.rb', line 18 def run opts=nil opts ||= {:server=>'webrick', :Port=>5125} optparser = optparse opts optparser.parse! root_dir = Config['root-dir'] ||= Config::ROOT_PATH plugin_dirs = Config.getvar('plugin-dir') || [root_dir + '/plugin'] Plugin.load_plugins plugin_dirs, Config app = @app builder = Rack::Builder.new { use Rack::Static, :urls=>['/css', '/js'], :root=>app.public_dir run app } if ENV['GATEWAY_INTERFACE'] Rack::Handler::CGI.run builder else if Rack.const_defined? :Server opts[:app] = builder Rack::Server.new(opts).start else Rack::Handler::WEBrick.run builder, opts end end end |