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
OBJECT_NAME_ATTR =

The name of the attribute that holds the object’s name

:displayName

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(includer) ⇒ Object

when this module is included, also extend our Class Methods



14
15
16
17
# File 'lib/jamf/api/jamf_pro/mixins/prestage.rb', line 14

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



274
275
276
277
# File 'lib/jamf/api/jamf_pro/mixins/prestage.rb', line 274

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)


267
268
269
# File 'lib/jamf/api/jamf_pro/mixins/prestage.rb', line 267

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



254
255
256
# File 'lib/jamf/api/jamf_pro/mixins/prestage.rb', line 254

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)


241
242
243
244
245
246
247
248
249
250
251
# File 'lib/jamf/api/jamf_pro/mixins/prestage.rb', line 241

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



287
288
289
# File 'lib/jamf/api/jamf_pro/mixins/prestage.rb', line 287

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

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



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

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