lib/avromatic/model/message_decoder.rb in avromatic-0.13.0.rc0 vs lib/avromatic/model/message_decoder.rb in avromatic-0.13.0.rc1

- old
+ new

@@ -47,20 +47,18 @@ Avromatic.build_schema_registry end # @return [Avromatic model] def decode(*args) - with_decode_args(*args) do |model, message_key, message_value| - model.avro_message_decode(message_key, message_value) - end + model, message_key, message_value = extract_decode_args(*args) + model.avro_message_decode(message_key, message_value) end # @return [Hash] def decode_hash(*args) - with_decode_args(*args) do |model, message_key, message_value| - model.avro_message_attributes(message_key, message_value) - end + model, message_key, message_value = extract_decode_args(*args) + model.avro_message_attributes(message_key, message_value) end private attr_reader :schema_names_by_id, :model_map, :schema_registry @@ -76,14 +74,14 @@ end # If two arguments are specified then the first is interpreted as the # message key and the second is the message value. If there is only one # arg then it is used as the message value. - def with_decode_args(*args) + def extract_decode_args(*args) message_key, message_value = extract_key_and_value(*args) model_key = model_key_for_message(message_key, message_value) raise UnexpectedKeyError.new(model_key) unless model_map.key?(model_key) - yield(model_map[model_key], message_key, message_value) + [model_map[model_key], message_key, message_value] end def schema_name_for_data(data) validate_magic_byte!(data) schema_id = extract_schema_id(data)