Sha256: fc43a0f962754ebf72732116a2aeea250d9103e06a1faefb461518054ea9d353

Contents?: true

Size: 786 Bytes

Versions: 14

Compression:

Stored size: 786 Bytes

Contents

require 'multi_json'

module Cucumber
  module WireSupport
    # Represents the packet of data sent over the wire as JSON data, containing
    # a message and a hash of arguments
    class WirePacket
      class << self
        def parse(raw)
          attributes = MultiJson.load(raw.strip)
          message = attributes[0]
          params  = attributes[1]
          new(message, params)
        end
      end

      attr_reader :message, :params

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

      def to_json
        packet = [@message]
        packet << @params if @params
        MultiJson.dump(packet)
      end

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

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
cucumber-2.1.0 lib/cucumber/wire_support/wire_packet.rb
cucumber-2.0.2 lib/cucumber/wire_support/wire_packet.rb
cucumber-2.0.1 lib/cucumber/wire_support/wire_packet.rb
cucumber-2.0.0 lib/cucumber/wire_support/wire_packet.rb
cucumber-2.0.0.rc.5 lib/cucumber/wire_support/wire_packet.rb
cucumber-2.0.0.rc.4 lib/cucumber/wire_support/wire_packet.rb
cucumber-2.0.0.rc.3 lib/cucumber/wire_support/wire_packet.rb
cucumber-2.0.0.rc.2 lib/cucumber/wire_support/wire_packet.rb
cucumber-2.0.0.rc.1 lib/cucumber/wire_support/wire_packet.rb
cucumber-2.0.0.beta.5 lib/cucumber/wire_support/wire_packet.rb
cucumber-2.0.0.beta.4 lib/cucumber/wire_support/wire_packet.rb
cucumber-2.0.0.beta.3 lib/cucumber/wire_support/wire_packet.rb
cucumber-2.0.0.beta.2 lib/cucumber/wire_support/wire_packet.rb
cucumber-2.0.0.beta.1 lib/cucumber/wire_support/wire_packet.rb