class Protobuf::Field::BaseFieldObjectDefinitions::RequiredRepeatedSetField

Public Class Methods

new(selph) click to toggle source
# File lib/protobuf/field/base_field_object_definitions.rb, line 225
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 231
        def call(values, value, ignore_nil_for_repeated, message_instance)
          if value.nil? && ignore_nil_for_repeated
            ::Protobuf.deprecator.deprecation_warning("['#{@fully_qualified_name}']=nil", "use an empty array instead of nil")
            return
          end

          unless value.is_a?(Array)
            fail TypeError, <<-TYPE_ERROR
                  Expected repeated value of type '#{@selph.type_class}'
                  Got '#{value.class}' for repeated protobuf field #{@selph.name}
            TYPE_ERROR
          end

          value = value.compact

          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::FieldArray.new(@selph)
            values[@fully_qualified_name].replace(value)
          end
        end