class Pantry::Communication::SerializeMessage::FromZeromq

Public Class Methods

new(parts) click to toggle source
# File lib/pantry/communication/serialize_message.rb, line 56
def initialize(parts)
  @parts = parts
end

Public Instance Methods

perform() click to toggle source
# File lib/pantry/communication/serialize_message.rb, line 60
def perform
  Pantry::Message.new.tap do |message|
    message.metadata = JSON.parse(@parts[1], symbolize_names: true)
    message.to       = @parts[0]
    message.body     = parse_body_parts(@parts[2..-1])
  end
end

Protected Instance Methods

parse_body_parts(body_parts) click to toggle source
# File lib/pantry/communication/serialize_message.rb, line 70
def parse_body_parts(body_parts)
  body_parts.map do |raw_part|
    part = raw_part.force_encoding("UTF-8")

    if part.start_with?(IS_JSON)
      JSON.parse(part[1..-1], symbolize_names: true) rescue part
    else
      raw_part
    end
  end
end