Class: EventHookClientServer::Refinements::Protobuf::NullableValues::HashProcessor
- Inherits:
-
Service
- Object
- Service
- EventHookClientServer::Refinements::Protobuf::NullableValues::HashProcessor
- Defined in:
- lib/event_hook_client_server/refinements/protobuf/nullable_values.rb
Overview
Recursively traverses hashes and arrays looking for a Hash value that looks like ‘{ value: ’something’ }‘ and who’s coresponding message type class name ends with ‘Value`. When found the hash key / array element is deleted and in it’s place the object stored under the ‘value` key is placed.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(hash, object, parent_hash = nil, parent_key = nil) ⇒ HashProcessor
constructor
A new instance of HashProcessor.
Methods inherited from Service
Constructor Details
#initialize(hash, object, parent_hash = nil, parent_key = nil) ⇒ HashProcessor
Returns a new instance of HashProcessor.
23 24 25 26 27 28 |
# File 'lib/event_hook_client_server/refinements/protobuf/nullable_values.rb', line 23 def initialize(hash, object, parent_hash = nil, parent_key = nil) @hash = hash @object = object @parent_hash = parent_hash @parent_key = parent_key end |
Instance Method Details
#call ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/event_hook_client_server/refinements/protobuf/nullable_values.rb', line 30 def call if value? && parent_hash parent_hash.delete(parent_key) if parent_hash.is_a?(Hash) parent_hash[parent_key] = hash[:value] return parent_hash[parent_key] end case hash when Hash then process_hash! when Array then process_array! else object end hash end |