Module: Jamf::Sitable
- Included in:
- AdvancedSearch, Computer, ComputerInvitation, ConfigurationProfile, Ebook, Group, MacApplication, MobileDevice, MobileDeviceApplication, PatchTitle, Peripheral, Policy, RestrictedSoftware, VPPAccount
- Defined in:
- lib/jamf/api/classic/api_objects/sitable.rb
Overview
A mix-in module that centralizes the code for handling objects which can be assigned a ‘site’ in the JSS.
Objects in the JSS present site data in the top-level :general Hash in the :site key which is a Hash with a :name and :id key.
Classes mixing in this module MUST:
Constant Summary collapse
- SITABLE =
Module Constants
true
- NO_SITE_NAME =
When no site has been assigned, this is the ‘name’ and id used
'None'.freeze
- NO_SITE_ID =
-1
- NON_SITES =
Setting the site to any of these values will unset the site
[ nil, '', 0, NO_SITE_NAME, NO_SITE_ID ].freeze
Instance Method Summary collapse
-
#site=(new_site) ⇒ void
Change the site of this object.
-
#site_assigned? ⇒ Boolean
Does this object have a site assigned?.
-
#site_id ⇒ Integer
The id of the site for this object.
-
#site_name ⇒ String
(also: #site)
The name of the site for this object.
-
#site_object ⇒ Jamf::Site
The Jamf::Site instance for this object’s site.
-
#unset_site ⇒ void
Set the site to nothing.
Instance Method Details
#site=(new_site) ⇒ void
This method returns an undefined value.
Change the site of this object. Any of the NON_SITES values will unset the site
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/jamf/api/classic/api_objects/sitable.rb', line 124 def site=(new_site) return nil unless updatable? || creatable? # unset the site? Use nil or an empty string if NON_SITES.include? new_site unset_site return end new_id = Jamf::Site.valid_id new_site, cnx: @cnx new_name = Jamf::Site.map_all_ids_to(:name, cnx: @cnx)[new_id] # no change, go home. return nil if new_name == @site_name raise Jamf::NoSuchItemError, "Site '#{new_site}' is not known to the JSS" unless new_id @site_name = new_name @site_id = new_id @need_to_update = true end |
#site_assigned? ⇒ Boolean
Does this object have a site assigned?
108 109 110 111 112 113 114 |
# File 'lib/jamf/api/classic/api_objects/sitable.rb', line 108 def site_assigned? if @site_name == NO_SITE_NAME false else !@site_name.nil? end end |
#site_id ⇒ Integer
The id of the site for this object.
91 92 93 |
# File 'lib/jamf/api/classic/api_objects/sitable.rb', line 91 def site_id @site_id || NO_SITE_ID end |
#site_name ⇒ String Also known as: site
The name of the site for this object. For backward compatibility, this is aliased to just ‘site’
82 83 84 |
# File 'lib/jamf/api/classic/api_objects/sitable.rb', line 82 def site_name @site_name || NO_SITE_NAME end |
#site_object ⇒ Jamf::Site
The Jamf::Site instance for this object’s site
99 100 101 102 |
# File 'lib/jamf/api/classic/api_objects/sitable.rb', line 99 def site_object return nil unless site_assigned? Jamf::Site.fetch id: @site_id end |
#unset_site ⇒ void
This method returns an undefined value.
Set the site to nothing
149 150 151 152 153 154 155 |
# File 'lib/jamf/api/classic/api_objects/sitable.rb', line 149 def unset_site # no change, go home return nil if @site_name.nil? @site_name = nil @site_id = nil @need_to_update = true end |