Class: AceMQ::AMQP::Patterns::Scheduler::Verbatim

Inherits:
Object
  • Object
show all
Defined in:
lib/acemq/amqp/patterns/scheduler.rb

Overview

Writes already-encoded bytes out unchanged, under the content type they were encoded as.

Publishing them through an ordinary codec would encode them a second time, and what arrives is JSON containing JSON. Publishing them with BytesCodec loses the content type, and what arrives cannot be decoded by the consumer that was waiting for it.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content_type) ⇒ Verbatim

Returns a new instance of Verbatim.



137
138
139
140
# File 'lib/acemq/amqp/patterns/scheduler.rb', line 137

def initialize(content_type)
  @content_type = content_type.to_s
  freeze
end

Instance Attribute Details

#content_type ⇒ Object (readonly)

Returns the value of attribute content_type.



142
143
144
# File 'lib/acemq/amqp/patterns/scheduler.rb', line 142

def content_type
  @content_type
end

Instance Method Details

#can_decode?(_content_type) ⇒ Boolean

Returns:

  • (Boolean)


154
# File 'lib/acemq/amqp/patterns/scheduler.rb', line 154

def can_decode?(_content_type) = false

#decode(_body) ⇒ Object

Raises:



150
151
152
# File 'lib/acemq/amqp/patterns/scheduler.rb', line 150

def decode(_body)
  raise DecodeError, "the scheduler only publishes"
end

#encode(payload) ⇒ Object

Raises:



144
145
146
147
148
# File 'lib/acemq/amqp/patterns/scheduler.rb', line 144

def encode(payload)
  return payload if payload.is_a?(String)

  raise EncodeError, "the scheduler moves bytes, not a #{payload.class}"
end