Class: Gcpc::Interceptors::Publisher::EncodeInterceptor

Inherits:
Publisher::BaseInterceptor
  • Object
show all
Defined in:
lib/gcpc/interceptors/publisher/encode_interceptor.rb

Overview

‘EncodeInterceptor` encodes a data and publish it as a String.

Constant Summary collapse

VALID_CONTENT_TYPES =
[
  "json",
  "protobuf",
]

Instance Method Summary collapse

Constructor Details

#initialize(content_type:) ⇒ EncodeInterceptor

Returns a new instance of EncodeInterceptor.



11
12
13
14
# File 'lib/gcpc/interceptors/publisher/encode_interceptor.rb', line 11

def initialize(content_type:)
  @content_type = content_type.to_s
  validate!
end

Instance Method Details

#publish(data, attributes) {|d, a| ... } ⇒ Object

Parameters:

  • data (#to_json, #to_proto)
  • attributes (Hash)

Yields:

  • (d, a)


18
19
20
21
22
# File 'lib/gcpc/interceptors/publisher/encode_interceptor.rb', line 18

def publish(data, attributes)
  d = encode(data)
  a = attributes.merge("content_type" => @content_type)
  yield d, a
end