Module: Cel::Protobuf::CelComparisonMode

Defined in:
lib/cel/ast/elements/protobuf.rb

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object



437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
# File 'lib/cel/ast/elements/protobuf.rb', line 437

def ==(other)
  super || begin
    return false unless other.is_a?(Protobuf.base_class)

    a1 = self
    a2 = other

    if a1.is_a?(Google::Protobuf::Any) && !a1.type_url.empty?
      a1 = a1.unpack(Object.const_get(Cel.package_to_module_name(a1.type_name)))
      a1.extend(CelComparisonMode)
    end

    if a2.is_a?(Google::Protobuf::Any) && !a2.type_url.empty?
      a2 = a2.unpack(Object.const_get(Cel.package_to_module_name(a2.type_name)))
    end

    return false unless a1.class == a2.class

    if a1.is_a?(Google::Protobuf::Any) && a1.type_url.empty?
      a2.is_a?(Google::Protobuf::Any) && a2.type_url.empty?
      return a1.value == a2.value
    end

    a1.class.descriptor.each do |field|
      f1 = a1.public_send(field.name)
      f1.extend(CelComparisonMode) if f1.is_a?(Protobuf.base_class)
      f2 = a2.public_send(field.name)
      return false unless f1 == f2
    end
    true
  end
end