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
46 47 48 49 50 51 |
# File 'lib/poisol/server.rb', line 46 def access_log log_file = File.open 'log/poisol_webrick.log', 'a+' [ [log_file, "#{WEBrick::AccessLog::COMBINED_LOG_FORMAT} %T"], ] end |
#attach_request_handling ⇒ Object
32 33 34 |
# File 'lib/poisol/server.rb', line 32 def attach_request_handling @server.mount '/', ExtendedServer end |
#attach_shutdown ⇒ Object
36 37 38 |
# File 'lib/poisol/server.rb', line 36 def attach_shutdown trap 'INT' do @server.shutdown end end |
#base_url ⇒ Object
28 29 30 |
# File 'lib/poisol/server.rb', line 28 def base_url "http://localhost:#{@port}" end |
#log ⇒ Object
40 41 42 43 44 |
# File 'lib/poisol/server.rb', line 40 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
18 19 20 21 22 23 24 25 26 |
# File 'lib/poisol/server.rb', line 18 def start port PoisolLog.info "Starting server... as http://localhost:#{port}" @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 |
#stop ⇒ Object
53 54 55 56 57 58 |
# File 'lib/poisol/server.rb', line 53 def stop if @server.present? @server.shutdown PoisolLog.info "Server is shutdown" end end |