Class: GRI::WMain

Inherits:
Object show all
Defined in:
lib/gri/wmain.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Parameters:

  • value

    the value to set the attribute app to.



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.options = 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