Class: Jamf::PatchTitle::Version

Inherits:
Object
  • Object
show all
Defined in:
lib/jamf/api/classic/api_objects/patch_title/version.rb

Overview

A Patch Software Title Version in the JSS.

This class corresponds to a “version” returned from the ‘patchsoftwaretitles’ resource of the API

Not only does each one have a ‘version’, e.g. ‘8.3.2b12’, but also knows its parent PatchTitle, the matching Jamf::Package, if any, and can report the names and ids of the computers that have it installed.

To set or change the Jamf::Package associated with a PatchTitle::Version, first fetch the corresponding SoftwareTitle, use the #package= method of the Version object in its #versions attribute, then save the PatchTitle back to the JSS.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, data) ⇒ Version

This should only be instantiated by the Jamf::PatchTitle that contains this version.



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/jamf/api/classic/api_objects/patch_title/version.rb', line 66

def initialize(title, data)
  @title = title
  @version = data[:software_version].to_s

  return if data[:package].to_s.empty?

  pid = data[:package][:id].to_i

  @package_id = pid < 1 ? :none : pid
  @package_name = data[:package][:name]
end

Instance Attribute Details

#package_idInteger (readonly)

Returns the id of the Jamf::Package that installs this PatchVersion, if defined.

Returns:

  • (Integer)

    the id of the Jamf::Package that installs this PatchVersion, if defined.



57
58
59
# File 'lib/jamf/api/classic/api_objects/patch_title/version.rb', line 57

def package_id
  @package_id
end

#package_nameString (readonly)

Returns the name of the Jamf::Package that installs this PatchVersion, if defined.

Returns:

  • (String)

    the name of the Jamf::Package that installs this PatchVersion, if defined



61
62
63
# File 'lib/jamf/api/classic/api_objects/patch_title/version.rb', line 61

def package_name
  @package_name
end

#versionString (readonly)

Returns the software version number for this PatchVersion. name_id is a unique identfier created from the patch name.

Returns:

  • (String)

    the software version number for this PatchVersion. name_id is a unique identfier created from the patch name



53
54
55
# File 'lib/jamf/api/classic/api_objects/patch_title/version.rb', line 53

def version
  @version
end

Instance Method Details

#computer_idsArray<Integer>

Returns The ids of #computers.

Returns:

  • (Array<Integer>)

    The ids of #computers



106
107
108
# File 'lib/jamf/api/classic/api_objects/patch_title/version.rb', line 106

def computer_ids
  computers.map { |c| c[:id] }
end

#computer_namesArray<Integer>

Returns The names of #computers.

Returns:

  • (Array<Integer>)

    The names of #computers



112
113
114
# File 'lib/jamf/api/classic/api_objects/patch_title/version.rb', line 112

def computer_names
  computers.map { |c| c[:name] }
end

#computer_serial_numbersArray<Integer>

Returns The serial_numbers of #computers.

Returns:

  • (Array<Integer>)

    The serial_numbers of #computers



118
119
120
# File 'lib/jamf/api/classic/api_objects/patch_title/version.rb', line 118

def computer_serial_numbers
  computers.map { |c| c[:serial_number] }
end

#computer_udidsArray<Integer>

Returns The udids of #computers.

Returns:

  • (Array<Integer>)

    The udids of #computers



124
125
126
# File 'lib/jamf/api/classic/api_objects/patch_title/version.rb', line 124

def computer_udids
  computers.map { |c| c[:udid] }
end

#computersArray<Hash>

Returns A hash of identifiers for each computer with this version installed.

Returns:

  • (Array<Hash>)

    A hash of identifiers for each computer with this version installed.



100
101
102
# File 'lib/jamf/api/classic/api_objects/patch_title/version.rb', line 100

def computers
  patch_report[:versions][version]
end

#package=(new_pkg) ⇒ Object

Assign a new Jamf::Package to this PatchTitle::Version. The Package must exist in the JSS. Be sure to call #update on the PatchTitle containing this Version.

Parameters:

  • new_pkg (String, Integer, Symbol)

    A name or id of a Jamf::Package. use :none to unset a package for this version.

Raises:



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/jamf/api/classic/api_objects/patch_title/version.rb', line 136

def package=(new_pkg)
  raise Jamf::UnsupportedError, "Packages can't be assigned to the Unkown version." if version == Jamf::PatchTitle::UNKNOWN_VERSION_ID

  pkgid =
    if new_pkg == :none
      :none
    else
      Jamf::Package.valid_id new_pkg, :refresh, cnx: @title.cnx
    end
  raise Jamf::NoSuchItemError, "No Jamf::Package matches '#{new_pkg}'" unless pkgid

  return if @package_id == pkgid

  @package_id = pkgid
  @package_name = pkgid == :none ? nil : Jamf::Package.map_all_ids_to(:name, cnx: @title.cnx)[pkgid]
  @title.changed_pkg_for_version version
end

#package_assigned?Boolean

Returns Has a package been assigned to this version?.

Returns:

  • (Boolean)

    Has a package been assigned to this version?



80
81
82
# File 'lib/jamf/api/classic/api_objects/patch_title/version.rb', line 80

def package_assigned?
  package_id != :none
end

#patch_reportObject Also known as: version_report, report

get the patch report for this version See PatchTitle.patch_report



86
87
88
# File 'lib/jamf/api/classic/api_objects/patch_title/version.rb', line 86

def patch_report
  @title.patch_report version
end

#pretty_print_instance_variablesArray

Remove the various cached data from the instance_variables used to create pretty-print (pp) output.

Returns:

  • (Array)

    the desired instance_variables



160
161
162
163
164
# File 'lib/jamf/api/classic/api_objects/patch_title/version.rb', line 160

def pretty_print_instance_variables
  vars = super
  vars.delete :@title
  vars
end

#total_computersInteger

Returns How many #computers have this version?.

Returns:

  • (Integer)

    How many #computers have this version?



94
95
96
# File 'lib/jamf/api/classic/api_objects/patch_title/version.rb', line 94

def total_computers
  patch_report[:total_computers]
end