Class: JSS::PatchTitle::Version

Inherits:
Object
  • Object
show all
Defined in:
lib/jss/api_object/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 JSS::Package, if any, and can report the names and ids of the computers that have it installed.

To set or change the JSS::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 JSS::PatchTitle that contains this version.



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/jss/api_object/patch_title/version.rb', line 67

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 JSS::Package that installs this PatchVersion, if defined.

Returns:

  • (Integer)

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



58
59
60
# File 'lib/jss/api_object/patch_title/version.rb', line 58

def package_id
  @package_id
end

#package_nameString (readonly)

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

Returns:

  • (String)

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



62
63
64
# File 'lib/jss/api_object/patch_title/version.rb', line 62

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



54
55
56
# File 'lib/jss/api_object/patch_title/version.rb', line 54

def version
  @version
end

Instance Method Details

#computer_idsArray<Integer>

Returns The ids of #computers.

Returns:

  • (Array<Integer>)

    The ids of #computers



107
108
109
# File 'lib/jss/api_object/patch_title/version.rb', line 107

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

#computer_namesArray<Integer>

Returns The names of #computers.

Returns:

  • (Array<Integer>)

    The names of #computers



113
114
115
# File 'lib/jss/api_object/patch_title/version.rb', line 113

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



119
120
121
# File 'lib/jss/api_object/patch_title/version.rb', line 119

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



125
126
127
# File 'lib/jss/api_object/patch_title/version.rb', line 125

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.



101
102
103
# File 'lib/jss/api_object/patch_title/version.rb', line 101

def computers
  patch_report[:versions][version]
end

#package=(new_pkg) ⇒ Object

Assign a new JSS::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 JSS::Package. use :none to unset a package for this version.

Raises:



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/jss/api_object/patch_title/version.rb', line 137

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

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

  return if @package_id == pkgid

  @package_id = pkgid
  @package_name = pkgid == :none ? nil : JSS::Package.map_all_ids_to(:name)[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?



81
82
83
# File 'lib/jss/api_object/patch_title/version.rb', line 81

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



87
88
89
# File 'lib/jss/api_object/patch_title/version.rb', line 87

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



161
162
163
164
165
# File 'lib/jss/api_object/patch_title/version.rb', line 161

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?



95
96
97
# File 'lib/jss/api_object/patch_title/version.rb', line 95

def total_computers
  patch_report[:total_computers]
end