Class: DevelopmentServer::Message
- Inherits:
-
Object
- Object
- DevelopmentServer::Message
- Defined in:
- lib/yodel/middleware/development_server.rb
Constant Summary collapse
- MESSAGE_TYPES =
{request: 0, response: 1, restart: 2, exit: 3}
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#data ⇒ Object
Returns the value of attribute data.
-
#env ⇒ Object
Returns the value of attribute env.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#message_type ⇒ Object
Returns the value of attribute message_type.
-
#status ⇒ Object
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
- #exit? ⇒ Boolean
-
#initialize(message_type) ⇒ Message
constructor
A new instance of Message.
- #request? ⇒ Boolean
- #response? ⇒ Boolean
- #restart? ⇒ Boolean
- #write(socket) ⇒ Object
Constructor Details
#initialize(message_type) ⇒ Message
Returns a new instance of Message.
20 21 22 |
# File 'lib/yodel/middleware/development_server.rb', line 20 def initialize() @message_type = end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
12 13 14 |
# File 'lib/yodel/middleware/development_server.rb', line 12 def body @body end |
#data ⇒ Object
Returns the value of attribute data.
12 13 14 |
# File 'lib/yodel/middleware/development_server.rb', line 12 def data @data end |
#env ⇒ Object
Returns the value of attribute env.
12 13 14 |
# File 'lib/yodel/middleware/development_server.rb', line 12 def env @env end |
#headers ⇒ Object
Returns the value of attribute headers.
12 13 14 |
# File 'lib/yodel/middleware/development_server.rb', line 12 def headers @headers end |
#message_type ⇒ Object
Returns the value of attribute message_type.
12 13 14 |
# File 'lib/yodel/middleware/development_server.rb', line 12 def @message_type end |
#status ⇒ Object
Returns the value of attribute status.
12 13 14 |
# File 'lib/yodel/middleware/development_server.rb', line 12 def status @status end |
Class Method Details
.read(socket) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/yodel/middleware/development_server.rb', line 24 def self.read(socket) = Message.new(nil) . = MESSAGE_TYPES.keys[read_int(socket)] if .request? || .response? length = read_int(socket) .data = Marshal.load(socket.read(length)) if .request? .data['rack.input'] = StringIO.new(.data['rack.input']) .data['rack.errors'] = STDERR elsif .response? .data[2] = [.data[2]] end end end |
Instance Method Details
#exit? ⇒ Boolean
18 |
# File 'lib/yodel/middleware/development_server.rb', line 18 def exit?; @message_type == :exit; end |
#request? ⇒ Boolean
15 |
# File 'lib/yodel/middleware/development_server.rb', line 15 def request?; @message_type == :request; end |
#response? ⇒ Boolean
16 |
# File 'lib/yodel/middleware/development_server.rb', line 16 def response?; @message_type == :response; end |
#restart? ⇒ Boolean
17 |
# File 'lib/yodel/middleware/development_server.rb', line 17 def restart?; @message_type == :restart; end |
#write(socket) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/yodel/middleware/development_server.rb', line 43 def write(socket) write_int(MESSAGE_TYPES[@message_type], socket) payload = nil if request? # convert input (StringIO) to a normal string, and # remove the reference to STDERR for transmission @env['rack.input'] = @env['rack.input'].read if @env['rack.input'].is_a?(StringIO) @env['rack.errors'] = nil payload = Marshal.dump(@env) elsif response? body = '' @body.each {|chunk| body << chunk.to_s} payload = Marshal.dump([@status, @headers, body]) end if payload write_int(payload.length, socket) socket.write(payload) end end |