class Protobuf::Field::BaseFieldObjectDefinitions::RequiredMapSetField

Public Class Methods

new(selph) click to toggle source
# File lib/protobuf/field/base_field_object_definitions.rb, line 175
def initialize(selph)
  @selph = selph
  @tag = selph.tag
  @fully_qualified_name = selph.fully_qualified_name
end

Public Instance Methods

call(values, value, _ignore_nil_for_repeated, message_instance) click to toggle source
# File lib/protobuf/field/base_field_object_definitions.rb, line 181
        def call(values, value, _ignore_nil_for_repeated, message_instance)
          unless value.is_a?(Hash)
            fail TypeError, <<-TYPE_ERROR
                    Expected map value
                    Got '#{value.class}' for map protobuf field #{@selph.name}
            TYPE_ERROR
          end

          if value.empty?
            values.delete(@fully_qualified_name)
            message_instance._protobuf_message_unset_required_field_tags << @tag
          else
            message_instance._protobuf_message_unset_required_field_tags.delete(@tag)
            values[@fully_qualified_name] ||= ::Protobuf::Field::FieldHash.new(@selph)
            values[@fully_qualified_name].replace(value)
          end
        end