Module: Windoo::Mixins::SoftwareTitle::ExtensionAttribute

Included in:
SoftwareTitle
Defined in:
lib/windoo/mixins/software_title/extension_attribute.rb

Overview

An module that manages the ExtensionAttribute in a SoftwareTitle.

Even though ‘extensionAttributes’ is plural, and they come from the server in an Array, at the moment there can only be one per SoftwareTitle.

This module hides that confusion and allows you to work with just one

If there’s already an extension attribute, you can access it from the #extensionAttribute getter, and use that to directly update its values.

Instance Method Summary collapse

Instance Method Details

#add_extensionAttribute(key:, displayName:, script:) ⇒ Integer

Add an ExtensionAttribute to this SoftwareTitle.

NOTE: There can be only one EA per SoftwareTitle. You will get an error if one already exists.

Parameters:

  • key (String)

    The name of the extension attribute as it appears in Jamf Pro NOTE: must be unique in the Title Editor AND Jamf Pro.

  • displayName (String)

    The name of the extension attribute as it appears in Title Editor

  • script (String)

    The script of that returns the value of the Extension Attribute on a computer. It must be a String that starts with ‘#!’

Returns:

  • (Integer)

    The id of the new Extension Attribute



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/windoo/mixins/software_title/extension_attribute.rb', line 65

def add_extensionAttribute(key:, displayName:, script:)
  if @extensionAttribute
    raise Windoo::AlreadyExistsError,
          'This SoftwareTitle already has an Extension Attribute. Either delete it before creating a new one, or update the existing one.'
  end

  @extensionAttribute = Windoo::ExtensionAttribute.create(
    container: self,
    key: key,
    displayName: displayName,
    script: script
  )

  @extensionAttribute.extensionAttributeId
end

#delete_extensionAttributeInteger

Delete the ExtensionAttribute from this SoftwareTitle

When deleting an EA via this method, it is deleted from the server immediately, there is no need to #save the SoftwareTitle

Returns:

  • (Integer)

    The id of the deleted Extension Attribute



89
90
91
92
93
94
95
96
97
98
# File 'lib/windoo/mixins/software_title/extension_attribute.rb', line 89

def delete_extensionAttribute
  return unless @extensionAttribute

  deleted_id = @extensionAttribute.delete
  @extensionAttribute = nil

  deleted_id
rescue Windoo::NoSuchItemError
  nil
end

#initialize(**init_data) ⇒ Object

Construcor



33
34
35
36
37
38
39
40
41
42
# File 'lib/windoo/mixins/software_title/extension_attribute.rb', line 33

def initialize(**init_data)
  super
  @extensionAttribute =
    if @init_data[:extensionAttributes]&.first
      Windoo::ExtensionAttribute.instantiate_from_container(
        container: self,
        **@init_data[:extensionAttributes].first
      )
    end
end