Class: Cucumber::Wire::DataPacket
- Inherits:
-
Object
- Object
- Cucumber::Wire::DataPacket
- Defined in:
- lib/cucumber/wire/data_packet.rb
Overview
Represents the packet of data sent over the wire as JSON data, containing a message and a hash of arguments
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Class Method Summary collapse
Instance Method Summary collapse
- #handle_with(handler) ⇒ Object
-
#initialize(message, params = nil) ⇒ DataPacket
constructor
A new instance of DataPacket.
- #to_json(*_args) ⇒ Object
Constructor Details
#initialize(message, params = nil) ⇒ DataPacket
Returns a new instance of DataPacket.
21 22 23 24 |
# File 'lib/cucumber/wire/data_packet.rb', line 21 def initialize(, params = nil) @message = @params = params end |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
19 20 21 |
# File 'lib/cucumber/wire/data_packet.rb', line 19 def @message end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
19 20 21 |
# File 'lib/cucumber/wire/data_packet.rb', line 19 def params @params end |
Class Method Details
.parse(raw) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/cucumber/wire/data_packet.rb', line 11 def parse(raw) attributes = JSON.parse(raw.strip) = attributes[0] params = attributes[1] new(, params) end |
Instance Method Details
#handle_with(handler) ⇒ Object
32 33 34 |
# File 'lib/cucumber/wire/data_packet.rb', line 32 def handle_with(handler) handler.send(:"handle_#{@message}", @params) end |
#to_json(*_args) ⇒ Object
26 27 28 29 30 |
# File 'lib/cucumber/wire/data_packet.rb', line 26 def to_json(*_args) packet = [@message] packet << @params if @params JSON.generate(packet) end |