Sha256: 1c5da8a83c5dcfd0b6df420d6db781310ec72acc97eaa8dce37219748c3ea27a
Contents?: true
Size: 775 Bytes
Versions: 7
Compression:
Stored size: 775 Bytes
Contents
require 'multi_json' module Lucid 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
7 entries across 7 versions & 1 rubygems