Module: JSS::Updatable
- Included in:
- AdvancedSearch, Building, Category, Computer, Department, ExtensionAttribute, Group, MobileDevice, MobileDeviceApplication, NetworkSegment, OSXConfigurationProfile, Package, Peripheral, PeripheralType, Policy, RemovableMacAddress, RestrictedSoftware, Script, Site, User, WebHook
- Defined in:
- lib/jss/api_object/updatable.rb,
lib/jss.rb
Overview
A mix-in module that allows objects to be updated in the JSS via the API.
When a JSS::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.
-
#update ⇒ Boolean
Save changes to the JSS.
Instance Attribute Details
#need_to_update ⇒ Boolean (readonly)
Returns do we have unsaved changes?.
65 66 67 |
# File 'lib/jss/api_object/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/jss/api_object/updatable.rb', line 77 def name=(newname) return nil if @name == newname raise JSS::UnsupportedError, "Editing #{self.class::RSRC_LIST_KEY} isn't yet supported. Please use other Casper workflows." unless UPDATABLE raise JSS::InvalidDataError, "Names can't be empty!" if newname.to_s.empty? raise JSS::AlreadyExistsError, "A #{self.class::RSRC_OBJECT_KEY} named '#{newname}' already exsists in the JSS" \ if self.class.all_names(:refresh).include? newname @name = newname @rest_rsrc = "#{self.class::RSRC_BASE}/name/#{CGI.escape @name}" if @rest_rsrc.include? '/name/' @need_to_update = true end |
#update ⇒ Boolean
Save changes to the JSS
92 93 94 95 96 97 98 99 100 |
# File 'lib/jss/api_object/updatable.rb', line 92 def update return nil unless @need_to_update raise JSS::UnsupportedError, "Editing #{self.class::RSRC_LIST_KEY} isn't yet supported. Please use other Casper workflows." unless UPDATABLE raise JSS::NoSuchItemError, "Not In JSS! Use #create to create this #{self.class::RSRC_OBJECT_KEY} in the JSS before updating it." unless @in_jss JSS.api_connection.put_rsrc @rest_rsrc, rest_xml @need_to_update = false refresh_icon if self_servable? @id end |