Class: Gcpc::Interceptors::Publisher::EncodeInterceptor
- Inherits:
-
Publisher::BaseInterceptor
- Object
- Publisher::BaseInterceptor
- Gcpc::Interceptors::Publisher::EncodeInterceptor
- 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
-
#initialize(content_type:) ⇒ EncodeInterceptor
constructor
A new instance of EncodeInterceptor.
- #publish(data, attributes) {|d, a| ... } ⇒ Object
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
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 |