Class: CloudEvents::Format::Multi
- Inherits:
-
Object
- Object
- CloudEvents::Format::Multi
- Defined in:
- lib/cloud_events/format.rb
Overview
A convenience formatter that checks multiple formats for one capable of handling the given input.
Instance Attribute Summary collapse
-
#formats ⇒ Array<Format>
readonly
The formats to check, in order.
Instance Method Summary collapse
-
#decode_data(**kwargs) ⇒ Object
Implements #decode_data.
-
#decode_event(**kwargs) ⇒ Object
Implements #decode_event.
-
#encode_data(**kwargs) ⇒ Object
Implements #encode_data.
-
#encode_event(**kwargs) ⇒ Object
Implements #encode_event.
-
#initialize(formats = [], &result_checker) ⇒ Multi
constructor
Create a multi format.
Constructor Details
#initialize(formats = [], &result_checker) ⇒ Multi
Create a multi format.
216 217 218 219 |
# File 'lib/cloud_events/format.rb', line 216 def initialize formats = [], &result_checker @formats = formats @result_checker = result_checker end |
Instance Attribute Details
#formats ⇒ Array<Format> (readonly)
The formats to check, in order.
226 227 228 |
# File 'lib/cloud_events/format.rb', line 226 def formats @formats end |
Instance Method Details
#decode_data(**kwargs) ⇒ Object
Implements CloudEvents::Format#decode_data
255 256 257 258 259 260 261 262 |
# File 'lib/cloud_events/format.rb', line 255 def decode_data **kwargs @formats.each do |elem| result = elem.decode_data(**kwargs) result = @result_checker.call result if @result_checker return result if result end nil end |
#decode_event(**kwargs) ⇒ Object
Implements CloudEvents::Format#decode_event
231 232 233 234 235 236 237 238 |
# File 'lib/cloud_events/format.rb', line 231 def decode_event **kwargs @formats.each do |elem| result = elem.decode_event(**kwargs) result = @result_checker.call result if @result_checker return result if result end nil end |
#encode_data(**kwargs) ⇒ Object
Implements CloudEvents::Format#encode_data
267 268 269 270 271 272 273 274 |
# File 'lib/cloud_events/format.rb', line 267 def encode_data **kwargs @formats.each do |elem| result = elem.encode_data(**kwargs) result = @result_checker.call result if @result_checker return result if result end nil end |
#encode_event(**kwargs) ⇒ Object
Implements CloudEvents::Format#encode_event
243 244 245 246 247 248 249 250 |
# File 'lib/cloud_events/format.rb', line 243 def encode_event **kwargs @formats.each do |elem| result = elem.encode_event(**kwargs) result = @result_checker.call result if @result_checker return result if result end nil end |