Module: Poisol::Server
Instance Method Summary collapse
- #access_log ⇒ Object
- #attach_request_handling ⇒ Object
- #attach_shutdown ⇒ Object
- #base_url ⇒ Object
- #log ⇒ Object
- #start(port) ⇒ Object
- #stop ⇒ Object
Instance Method Details
#access_log ⇒ Object
39 40 41 42 43 44 |
# File 'lib/poisol/server.rb', line 39 def access_log log_file = File.open 'log/poisol_webrick.log', 'a+' [ [log_file, WEBrick::AccessLog::COMBINED_LOG_FORMAT], ] end |
#attach_request_handling ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/poisol/server.rb', line 20 def attach_request_handling @server.mount_proc '/' do |req, res| stub_response = ResponseMapper.map(req) res.status = stub_response.status res.body = stub_response.body.to_json res.content_type = 'application/json' end end |
#attach_shutdown ⇒ Object
29 30 31 |
# File 'lib/poisol/server.rb', line 29 def attach_shutdown trap 'INT' do @server.shutdown end end |
#base_url ⇒ Object
16 17 18 |
# File 'lib/poisol/server.rb', line 16 def base_url "http://localhost:#{@port}" end |
#log ⇒ Object
33 34 35 36 37 |
# File 'lib/poisol/server.rb', line 33 def log FileUtils.mkdir_p "log" unless File.exists?("log") log_file = File.open 'log/poisol_webrick.log', 'a+' WEBrick::Log.new log_file end |
#start(port) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/poisol/server.rb', line 5 def start port PoisolLog.info "Starting server... as http://localhost:#{port}" require 'webrick' @server = WEBrick::HTTPServer.new :Port => port, :Logger => log, :AccessLog => access_log @port = port attach_shutdown attach_request_handling Thread.new{@server.start} PoisolLog.info "Server Started at http://localhost:#{port}" end |