Class: Google::Ads::GoogleAds::FieldMaskUtil
- Inherits:
-
Object
- Object
- Google::Ads::GoogleAds::FieldMaskUtil
- Defined in:
- lib/google/ads/google_ads/field_mask_util.rb
Overview
Utility for constructing FieldMask objects.
Copied from C# implementation courtesy of [email protected]
Constant Summary collapse
- WRAPPER_TYPES =
[Google::Protobuf::DoubleValue, Google::Protobuf::FloatValue, Google::Protobuf::Int64Value, Google::Protobuf::UInt64Value, Google::Protobuf::Int32Value, Google::Protobuf::UInt32Value, Google::Protobuf::BoolValue, Google::Protobuf::StringValue, Google::Protobuf::BytesValue].freeze
Class Method Summary collapse
-
.all_set_fields_of(obj) ⇒ Object
Construct a field mask containing any fields set on the given object.
-
.compare(original, modified) ⇒ Google::Protobuf::FieldMask
Creates Google::Protobuf::FieldMask objects based on the difference between two objects.
-
.with(obj) { ... } ⇒ Google::Protobuf::FieldMask
Construct a field mask containing any changes to the object made in the given block.
Class Method Details
.all_set_fields_of(obj) ⇒ Object
Construct a field mask containing any fields set on the given object.
Example:
obj = MyObject.new
obj.some_property = 1
obj.other_property = 2
mask = FieldMaskUtil.all_set_fields_of obj
# the mask will contain the present properties "some_property" and
# "other_property"
api_client.mutate obj, mask
return [Google::Protobuf::FieldMask] the computed mask
70 71 72 73 |
# File 'lib/google/ads/google_ads/field_mask_util.rb', line 70 def self.all_set_fields_of(obj) new_instance = obj.class.new compare_obj(Google::Protobuf::FieldMask.new, '', new_instance, obj) end |
.compare(original, modified) ⇒ Google::Protobuf::FieldMask
Creates Google::Protobuf::FieldMask objects based on the difference between two objects.
81 82 83 84 85 |
# File 'lib/google/ads/google_ads/field_mask_util.rb', line 81 def self.compare(original, modified) raise 'nil cannot be compared' if original.nil? || modified.nil? raise 'objects of different types cannot be compared' if original.class != modified.class compare_obj(Google::Protobuf::FieldMask.new, '', original, modified) end |
.with(obj) { ... } ⇒ Google::Protobuf::FieldMask
Construct a field mask containing any changes to the object made in the given block.
Example:
obj = MyObject.new
obj.some_property = 1
mask = FieldMaskUtil.with obj do
obj.other_property = 2
end
# the mask will contain the changed property "other_property"
api_client.mutate obj, mask
47 48 49 50 51 52 |
# File 'lib/google/ads/google_ads/field_mask_util.rb', line 47 def self.with(obj) raise 'nil cannot be compared' if obj.nil? original = obj.class.decode(obj.class.encode(obj)) yield obj compare original, obj end |