Module: Jamf::Updatable
- Included in:
- AdvancedSearch, Building, Category, Computer, ConfigurationProfile, Department, DirectoryBinding, DiskEncryptionConfiguration, DockItem, ExtensionAttribute, Group, IBeacon, MacApplication, MobileDevice, MobileDeviceApplication, NetworkSegment, Package, PatchPolicy, PatchSource, PatchTitle, Peripheral, PeripheralType, Policy, Printer, RemovableMacAddress, RestrictedSoftware, Script, Site, User, VPPAccount, WebHook
- Defined in:
- lib/jamf/api/classic/api_objects/updatable.rb
Overview
A mix-in module that allows objects to be updated in the JSS via the API.
When a Jamf::APIObject subclass includes this module, instances of that subclass can be modified in the JSS using the #update or APIObject#save methods.
Such classes should define setter methods for any values that they wish to modify, such as the #name= method defined here. Those setter methods must:
-
ensure the validity of the data they accept.
-
set @need_to_update to true, indicating that the local object no longer matches the JSS, and the changes should be pushed to the server with #update
Classes mixing this module must provide a #rest_xml instance method that returns the XML String to be submitted to the API for object updating.
Constant Summary collapse
- UPDATABLE =
Constants
true
Instance Attribute Summary collapse
-
#need_to_update ⇒ Boolean
readonly
Do we have unsaved changes?.
Instance Method Summary collapse
-
#name=(newname) ⇒ void
Change the name of this item Remember to #update to push changes to the server.
Instance Attribute Details
#need_to_update ⇒ Boolean (readonly)
Returns do we have unsaved changes?.
65 66 67 |
# File 'lib/jamf/api/classic/api_objects/updatable.rb', line 65 def need_to_update @need_to_update end |
Instance Method Details
#name=(newname) ⇒ void
This method returns an undefined value.
Change the name of this item Remember to #update to push changes to the server.
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/jamf/api/classic/api_objects/updatable.rb', line 77 def name=(newname) return nil if @name == newname raise Jamf::UnsupportedError, "Editing #{self.class::RSRC_LIST_KEY} isn't yet supported. Please use other Casper workflows." unless updatable? raise Jamf::InvalidDataError, "Names can't be empty!" if newname.to_s.empty? raise Jamf::AlreadyExistsError, "A #{self.class::RSRC_OBJECT_KEY} named '#{newname}' already exsists in the JSS" \ if self.class.all_names(:refresh, cnx: @cnx).include? newname @name = newname @rest_rsrc = "#{self.class::RSRC_BASE}/name/#{CGI.escape @name.to_s}" if @rest_rsrc.include? '/name/' @need_to_update = true end |