Sha256: 51836c0301245e98e4be0142f388ec3418aecf4b22e4b7dc5bd46d08a844cc4f

Contents?: true

Size: 778 Bytes

Versions: 27

Compression:

Stored size: 778 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
        packet.to_json
      end

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

Version data entries

27 entries across 25 versions & 2 rubygems

Version Path
honeybadger-2.4.0 vendor/gems/ruby/2.2.0/gems/cucumber-1.3.18/lib/cucumber/wire_support/wire_packet.rb
honeybadger-2.4.0 vendor/gems/ruby/1.9.1/gems/cucumber-1.3.18/lib/cucumber/wire_support/wire_packet.rb
honeybadger-2.4.0 vendor/gems/ruby/2.1.0/gems/cucumber-1.3.16/lib/cucumber/wire_support/wire_packet.rb
cucumber-1.3.20 lib/cucumber/wire_support/wire_packet.rb
cucumber-1.3.19 lib/cucumber/wire_support/wire_packet.rb
cucumber-1.3.18 lib/cucumber/wire_support/wire_packet.rb
cucumber-1.3.17 lib/cucumber/wire_support/wire_packet.rb
cucumber-1.3.16 lib/cucumber/wire_support/wire_packet.rb
cucumber-1.3.15 lib/cucumber/wire_support/wire_packet.rb
cucumber-1.3.14 lib/cucumber/wire_support/wire_packet.rb
cucumber-1.3.13 lib/cucumber/wire_support/wire_packet.rb
cucumber-1.3.12 lib/cucumber/wire_support/wire_packet.rb
cucumber-1.3.11 lib/cucumber/wire_support/wire_packet.rb
cucumber-1.3.10 lib/cucumber/wire_support/wire_packet.rb
cucumber-1.3.9 lib/cucumber/wire_support/wire_packet.rb
cucumber-1.3.8 lib/cucumber/wire_support/wire_packet.rb
cucumber-1.3.7 lib/cucumber/wire_support/wire_packet.rb
cucumber-1.3.6 lib/cucumber/wire_support/wire_packet.rb
cucumber-1.3.5 lib/cucumber/wire_support/wire_packet.rb
cucumber-1.3.4 lib/cucumber/wire_support/wire_packet.rb