Class: Rubyists::Leopard::MessageWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/leopard/message_wrapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nats_msg) ⇒ MessageWrapper

Returns a new instance of MessageWrapper.

Parameters:

  • nats_msg (NATS::Message)

    The NATS message to wrap.



20
21
22
23
24
# File 'lib/leopard/message_wrapper.rb', line 20

def initialize(nats_msg)
  @raw     = nats_msg
  @data    = parse_data(nats_msg.data)
  @headers = nats_msg.header.to_h
end

Instance Attribute Details

#dataNATS::Message, Object (readonly)

Returns:

  • (NATS::Message)

    The original NATS message.

  • (Object)

    The parsed data from the NATS message.



13
# File 'lib/leopard/message_wrapper.rb', line 13

attr_reader :raw, :data

#headersHash

Returns The headers from the NATS message.

Returns:

  • (Hash)

    The headers from the NATS message.



17
18
19
# File 'lib/leopard/message_wrapper.rb', line 17

def headers
  @headers
end

#rawNATS::Message, Object (readonly)

Returns:

  • (NATS::Message)

    The original NATS message.

  • (Object)

    The parsed data from the NATS message.



13
14
15
# File 'lib/leopard/message_wrapper.rb', line 13

def raw
  @raw
end

Instance Method Details

#respond(payload) ⇒ void

This method returns an undefined value.

Parameters:

  • payload (Object)

    The payload to respond with.



29
30
31
32
# File 'lib/leopard/message_wrapper.rb', line 29

def respond(payload)
  raw.header = headers unless headers.empty?
  raw.respond(serialize(payload))
end

#respond_with_error(err) ⇒ void

This method returns an undefined value.

Parameters:

  • err (String, Exception)

    The error message or exception to respond with.



37
38
39
# File 'lib/leopard/message_wrapper.rb', line 37

def respond_with_error(err)
  raw.respond_with_error(err.to_s)
end