Class: Rosendo::Server
- Inherits:
-
Object
- Object
- Rosendo::Server
- Defined in:
- lib/rosendo/server.rb
Defined Under Namespace
Classes: Stop
Instance Attribute Summary collapse
-
#out ⇒ Object
readonly
Returns the value of attribute out.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
-
#initialize(app, args = {}) ⇒ Server
constructor
A new instance of Server.
- #server ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(app, args = {}) ⇒ Server
Returns a new instance of Server.
8 9 10 11 12 |
# File 'lib/rosendo/server.rb', line 8 def initialize(app, args = {}) @app = app @port = args[:port] || '2000' @out = args[:out] || STDOUT end |
Instance Attribute Details
#out ⇒ Object (readonly)
Returns the value of attribute out.
7 8 9 |
# File 'lib/rosendo/server.rb', line 7 def out @out end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
7 8 9 |
# File 'lib/rosendo/server.rb', line 7 def port @port end |
Instance Method Details
#server ⇒ Object
33 34 35 |
# File 'lib/rosendo/server.rb', line 33 def server @server ||= TCPServer.new(@port) end |
#start ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rosendo/server.rb', line 14 def start out.puts "== Rosendo is rocking the stage on #{port}" out.puts ">> Listening on 0.0.0.0:#{port}, CTRL+C to stop" loop do begin client = server.accept request = Request.new(client) response = Response.new(client) @app.process(request, response) response.respond out.puts "#{request.method} #{request.url} #{response.status} #{response.body.size}" rescue Stop server.close out.puts "== Rosendo has left the building (everybody goes crazy)" end end end |