Class: Karafka::Params::Params
- Inherits:
-
Object
- Object
- Karafka::Params::Params
- Extended by:
- Forwardable
- Defined in:
- lib/karafka/params/params.rb
Overview
It provides lazy loading not only until the first usage, but also allows us to skip using deserializer until we execute our logic. That way we can operate with heavy-deserialization data without slowing down the whole application.
Instance Attribute Summary collapse
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#raw_payload ⇒ Object
readonly
Returns the value of attribute raw_payload.
Instance Method Summary collapse
-
#deserialized? ⇒ Boolean
Did given params payload were deserialized already.
-
#initialize(raw_payload, metadata) ⇒ Params
constructor
A new instance of Params.
-
#payload ⇒ Object
Lazy-deserialized data (deserialized upon first request).
Constructor Details
#initialize(raw_payload, metadata) ⇒ Params
18 19 20 21 22 23 |
# File 'lib/karafka/params/params.rb', line 18 def initialize(raw_payload, ) @raw_payload = raw_payload = @deserialized = false @payload = nil end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
12 13 14 |
# File 'lib/karafka/params/params.rb', line 12 def end |
#raw_payload ⇒ Object (readonly)
Returns the value of attribute raw_payload.
12 13 14 |
# File 'lib/karafka/params/params.rb', line 12 def raw_payload @raw_payload end |
Instance Method Details
#deserialized? ⇒ Boolean
37 38 39 |
# File 'lib/karafka/params/params.rb', line 37 def deserialized? @deserialized end |
#payload ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/karafka/params/params.rb', line 26 def payload return @payload if deserialized? @payload = deserialize # We mark deserialization as successful after deserialization, as in case of an error # this won't be falsely set to true @deserialized = true @payload end |