Class: SchemaRD::WebServer
- Inherits:
-
Object
- Object
- SchemaRD::WebServer
- Defined in:
- lib/schemard/web_server.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#initialize(config) ⇒ WebServer
constructor
A new instance of WebServer.
- #setup(srv, options) ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(config) ⇒ WebServer
Returns a new instance of WebServer.
7 8 9 |
# File 'lib/schemard/web_server.rb', line 7 def initialize(config) @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/schemard/web_server.rb', line 6 def config @config end |
Instance Method Details
#setup(srv, options) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/schemard/web_server.rb', line 10 def setup(srv, ) Signal.trap("INT"){ srv.shutdown } Signal.trap("TERM"){ srv.shutdown } # アクションメソッド srv.mount_proc '/' do |req, res| controller = SchemaRD::Controller.new(self.config) case req.path when "/", "/index" controller.index(req, res) when /\/tables\/.+/ controller.show(req, res) if req.request_method == "GET" controller.update(req, res) if req.request_method == "POST" when /.*\.(js|css|ico)/ controller.static_file(req, res) else res.status = Rack::Utils.status_code(404) end end end |
#start ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/schemard/web_server.rb', line 31 def start() = { :Host => config.webserver_host, :Port => config.webserver_port, :ServerType => WEBrick::SimpleServer, :Logger => WEBrick::Log.new(config.log_output), } begin srv = WEBrick::HTTPServer.new(); setup(srv, ) srv.start rescue Errno::EADDRINUSE => e ([:Logger] || Logger.new(STDOUT)).error("#{__FILE__}: #{e.to_s}") end end |