Module: JSS::Sitable
- Included in:
- AdvancedSearch, Computer, ComputerInvitation, ConfigurationProfile, EBook, Group, MacApplication, MobileDevice, MobileDeviceApplication, Peripheral, Policy, RestrictedSoftware
- Defined in:
- lib/jss/api_object/sitable.rb,
lib/jss.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 ⇒ JSS::Site
The JSS::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
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/jss/api_object/sitable.rb', line 120 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 = JSS::Site.valid_id new_site, api: @api new_name = JSS::Site.map_all_ids_to(:name, api: @api)[new_id] # no change, go home. return nil if new_name == @site_name raise JSS::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 |
# File 'lib/jss/api_object/sitable.rb', line 108 def site_assigned? !@site_name.nil? end |
#site_id ⇒ Integer
The id of the site for this object.
91 92 93 |
# File 'lib/jss/api_object/sitable.rb', line 91 def site_id @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/jss/api_object/sitable.rb', line 82 def site_name @site_name end |
#site_object ⇒ JSS::Site
The JSS::Site instance for this object’s site
99 100 101 102 |
# File 'lib/jss/api_object/sitable.rb', line 99 def site_object return nil unless site_assigned? JSS::Site.new id: @site_id end |
#unset_site ⇒ void
This method returns an undefined value.
Set the site to nothing
145 146 147 148 149 150 151 |
# File 'lib/jss/api_object/sitable.rb', line 145 def unset_site # no change, go home return nil if @site_name.nil? @site_name = nil @site_id = nil @need_to_update = true end |