Class: Karafka::Params::Params
- Inherits:
-
Hash
- Object
- Hash
- Karafka::Params::Params
- 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 Method Summary collapse
-
#[](key) ⇒ Object
Overrides ‘Hash#[]` to allow lazy deserialization of payload.
-
#deserialize! ⇒ Karafka::Params::Params
This method will trigger deserializer execution.
Instance Method Details
#[](key) ⇒ Object
Overrides ‘Hash#[]` to allow lazy deserialization of payload. This allows us to fetch metadata without actually triggering deserialization of the payload until it is needed
47 48 49 50 51 |
# File 'lib/karafka/params/params.rb', line 47 def [](key) # Payload will be deserialized only when we request for it. deserialize! if key == 'payload' super end |
#deserialize! ⇒ Karafka::Params::Params
Returns This method will trigger deserializer execution. If we decide to retrieve data, deserializer will be executed to get data. Output of that will be merged to the current object. This object will be also marked as already deserialized, so we won’t deserialize it again.
57 58 59 60 61 62 63 |
# File 'lib/karafka/params/params.rb', line 57 def deserialize! return self if self['deserialized'] self['deserialized'] = true self['payload'] = deserialize self end |