Module: Jamf::Prestage

Included in:
ComputerPrestage, MobileDevicePrestage
Defined in:
lib/jamf/api/jamf_pro/mixins/prestage.rb

Overview

The Shared Code for ComputerPrestage and MobileDevicePrestage

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

SCOPE_PATH =

The scope of a prestage is all the SN’s that have been assigned to it

'scope'.freeze
ALL_SCOPES_OBJECT =

The class-level scopes method returns one of these objects

Jamf::OAPISchemas::PrestageScopeV2
INSTANCE_SCOPE_OBJECT =

the instance level scope method or the class level serials_for_prestage method returns one of these.

Jamf::OAPISchemas::PrestageScopeResponseV2
ALT_IDENTIFIERS =

Identifiers not marked in the superclass’s OAPI_PROPERTIES constant which usually only marks ‘:id’. These values are unique in the collection

%i[profileUuid].freeze
NON_UNIQUE_IDENTIFIERS =

Values which are useful as identifiers, but are not necessarily unique in the collection - e.g. more than one computer can have the same name WARNING When more than one item in the collection has the same value for one of these fields, which one is used, returned, selected, is undefined You Have Been Warned!

%i[displayName].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(includer) ⇒ Object

when this module is included, also extend our Class Methods



32
33
34
35
# File 'lib/jamf/api/jamf_pro/mixins/prestage.rb', line 32

def self.included(includer)
  Jamf.load_msg "--> #{includer} is including Jamf::Prestage"
  includer.extend(ClassMethods)
end

Instance Method Details

#assign(*sns_to_assign) ⇒ Object Also known as: add

Assign



289
290
291
292
# File 'lib/jamf/api/jamf_pro/mixins/prestage.rb', line 289

def assign(*sns_to_assign)
  scope = self.class.assign(*sns_to_assign, to_prestage: @id, cnx: @cnx)
  @versionLock = scope.versionLock
end

#assigned?(sn) ⇒ Boolean Also known as: include?, scoped?

Is this SN assigned to this prestage?

This method uses the instance’s scope object, from a different API path than the class-level .assigned? method.

Parameters:

  • sn (String)

    the sn to look for

Returns:

  • (Boolean)


282
283
284
# File 'lib/jamf/api/jamf_pro/mixins/prestage.rb', line 282

def assigned?(sn)
  assigned_sns.include? sn
end

#assigned_snsArray<String>

Returns the serialnumbers assigned to this prestage.

Returns:

  • (Array<String>)

    the serialnumbers assigned to this prestage



269
270
271
# File 'lib/jamf/api/jamf_pro/mixins/prestage.rb', line 269

def assigned_sns
  scope.assignments.map(&:serialNumber)
end

#scope(refresh = false) ⇒ PrestageScope

The scope data for this prestage -

Parameters:

  • refresh (Boolean) (defaults to: false)

    reload from the API? DEPRECATED: the data is always read from the API. If making many calls at once, consisider capturing the data in your own variable

Returns:

  • (PrestageScope)


256
257
258
259
260
261
262
263
264
265
266
# File 'lib/jamf/api/jamf_pro/mixins/prestage.rb', line 256

def scope(refresh = false) # rubocop:disable Lint/UnusedMethodArgument
  scope = INSTANCE_SCOPE_OBJECT.new @cnx.get(scope_path)

  # TODO: is this the best way to deal with fetching a scope that
  # is more updated than the rest of the object?
  unless scope.versionLock == @versionLock
    raise Jamf::VersionLockError, "The #{self.class} '#{displayName}' has been modified since it was fetched. Please refetch and try again"
  end

  scope
end

#scope_pathObject

The scope endpoint for this instance



302
303
304
# File 'lib/jamf/api/jamf_pro/mixins/prestage.rb', line 302

def scope_path
  @scope_path ||= self.class.scope_path(id)
end

#unassign(*sns_to_unassign) ⇒ Object Also known as: remove



295
296
297
298
# File 'lib/jamf/api/jamf_pro/mixins/prestage.rb', line 295

def unassign(*sns_to_unassign)
  scope = self.class.unassign(*sns_to_unassign, from_prestage: @id, cnx: @cnx)
  @versionLock = scope.versionLock
end