Class: Cucumber::WireSupport::WirePacket

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber/wire_support/wire_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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, params = nil) ⇒ WirePacket

Returns a new instance of WirePacket.



19
20
21
# File 'lib/cucumber/wire_support/wire_packet.rb', line 19

def initialize(message, params = nil)
  @message, @params = message, params
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



17
18
19
# File 'lib/cucumber/wire_support/wire_packet.rb', line 17

def message
  @message
end

#paramsObject (readonly)

Returns the value of attribute params.



17
18
19
# File 'lib/cucumber/wire_support/wire_packet.rb', line 17

def params
  @params
end

Class Method Details

.parse(raw) ⇒ Object



9
10
11
12
13
14
# File 'lib/cucumber/wire_support/wire_packet.rb', line 9

def parse(raw)
  attributes = MultiJson.load(raw.strip)
  message = attributes[0]
  params  = attributes[1]
  new(message, params)
end

Instance Method Details

#handle_with(handler) ⇒ Object



29
30
31
# File 'lib/cucumber/wire_support/wire_packet.rb', line 29

def handle_with(handler)
  handler.send("handle_#{@message}", @params)
end

#to_jsonObject



23
24
25
26
27
# File 'lib/cucumber/wire_support/wire_packet.rb', line 23

def to_json
  packet = [@message]
  packet << @params if @params
  packet.to_json
end