Sha256: 5d83be886d48a14fa32df225ebd09e7876b84087ae2d957c7c62cdda2fc913c1

Contents?: true

Size: 841 Bytes

Versions: 2

Compression:

Stored size: 841 Bytes

Contents

require 'active_support/core_ext/hash/indifferent_access'
require 'forwardable'

module Asynk
  class Message
    extend Forwardable

    attr_reader :delivery_info, :properties, :payload, :body

    def initialize(delivery_info, properties, payload)
      @delivery_info = delivery_info
      @properties    = properties
      @payload       = payload
      @body          = JSON.parse(payload).with_indifferent_access
    end

    def_delegator :@body, :[]
    def_delegators :@properties, :message_id, :timestamp
    def_delegators :@delivery_info, :routing_key, :exchange


    def to_s
      attrs = { :@body => body.to_s, message_id: message_id,
                timestamp: timestamp, routing_key: routing_key }
      "#<Message #{attrs.map { |k,v| "#{k}=#{v.inspect}" }.join(', ')}>"
    end

    alias_method :inspect, :to_s
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
asynk-0.0.2 lib/asynk/message.rb
asynk-0.0.1 lib/asynk/message.rb