Method: Jamf::OAPIObject#unsaved_changes

Defined in:
lib/jamf/api/jamf_pro/base_classes/oapi_object.rb

#unsaved_changesObject

a hash of all unsaved changes



382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
# File 'lib/jamf/api/jamf_pro/base_classes/oapi_object.rb', line 382

def unsaved_changes
  return {} unless self.class.mutable?

  @unsaved_changes ||= {}

  changes = @unsaved_changes.dup

  self.class::OAPI_PROPERTIES.each do |attr_name, attr_def|
    # skip non-Class attrs
    next unless attr_def[:class].is_a? Class

    # the current value of the thing, e.g. a Location
    # which may have unsaved changes
    value = instance_variable_get "@#{attr_name}"

    # skip those that don't have any changes
    next unless value.respond_to? :unsaved_changes?

    attr_changes = value.unsaved_changes
    next if attr_changes.empty?

    # add the sub-changes to ours
    changes[attr_name] = attr_changes
  end
  changes[:ext_attrs] = ext_attrs_unsaved_changes if self.class.include? Jamf::Extendable
  changes
end