lib/jss/api_object/extendable.rb in ruby-jss-0.10.0a3 vs lib/jss/api_object/extendable.rb in ruby-jss-0.10.0
- old
+ new
@@ -137,10 +137,15 @@
end # case
@ext_attrs[ea[:name]] = ea[:value]
end # each do ea
+
+ # remember changes as they happen so
+ # we only send changes back to the server.
+ @changed_eas = []
+
end
###
### Set the value of an extension attribute
###
@@ -157,10 +162,13 @@
###
### @return [void]
###
def set_ext_attr(name, value)
+ # if we don't currently have any need to update(cuz we have recently), reset the list of changes to push
+ @changed_eas = [] unless @need_to_update
+
# this will raise an exception if the name doesn't exist
ea_def = self.class::EXT_ATTRIB_CLASS.new :name => name
unless JSS::ExtensionAttribute::EDITABLE_INPUT_TYPES.include? ea_def.input_type
raise JSS::UnsupportedError, "The value for #{name} cannot be modified. It is gathered during inventory updates."
@@ -182,24 +190,25 @@
@extension_attributes.each do |ea|
ea[:value] = value if ea[:name] == name
end
@ext_attrs[name] = value
-
+ @changed_eas << name
@need_to_update = true
+
end
###
### @api private
###
### @return [REXML::Element] An <extension_attribute> element to be
### included in the rest_xml of objects that mix-in this module.
###
def ext_attr_xml
-
+ @changed_eas ||= []
eaxml = REXML::Element.new('extension_attributes')
-
@extension_attributes.each do |ea|
+ next unless @changed_eas.include? ea[:name]
ea_el = eaxml.add_element('extension_attribute')
ea_el.add_element('name').text = ea[:name]
if ea[:type] == "Date"
begin