Class: Jamf::ExtensionAttributeValue

Inherits:
JSONObject show all
Defined in:
lib/jamf/api/json_objects/extension_attribute_value.rb

Overview

An extension attribute in Jamf Pro

Constant Summary collapse

OBJECT_MODEL =
{

  # @!attribute [r] id
  #   The id of the attribute defining this value
  #   @return [Integer]
  id: {
    class: :integer,
    readonly: true
  },

  # @!attribute [r] name
  #   The name of the attribute defining this value
  #   @return [String]
  name: {
    class: :string,
    readonly: true
  },

  # @!attribute [r] type
  #   The value_type of this value
  #   @return [String]
  type: {
    class: :string,
    enum: Jamf::ExtensionAttribute::VALUE_TYPES,
    readonly: true
  },

  # @!attribute [r] value
  #   The value stored for this managed object for this ext attr
  #   Settable via #new_value=
  #   @return [String]
  value: {
    class: :string,
    readonly: true # settable via Extendable#set_ext_attr
  }

}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, cnx: Jamf.cnx) ⇒ ExtensionAttributeValue

TODO: The WebApp doesn’t seem to support enforcement of Data types..

I can enter any string as a DATE ea, an that string comes through as the
value.


76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/jamf/api/json_objects/extension_attribute_value.rb', line 76

def initialize(data, cnx: Jamf.cnx)
  super
  return if @value.nil?
  @value =
    case @type
    when :integer
      @value.j_integer? ? @value.to_i : "INVALID INTEGER: #{@value}"
    when :date
      Jamf::TimeStamp.new @value, cnx: cnx
    else
      @value
    end # case
end

Instance Attribute Details

#idInteger (readonly)

The id of the attribute defining this value

Returns:

  • (Integer)


# File 'lib/jamf/api/json_objects/extension_attribute_value.rb', line 34

#nameString (readonly)

The name of the attribute defining this value

Returns:



# File 'lib/jamf/api/json_objects/extension_attribute_value.rb', line 42

#typeString (readonly)

The value_type of this value

Returns:



# File 'lib/jamf/api/json_objects/extension_attribute_value.rb', line 50

#valueString (readonly)

The value stored for this managed object for this ext attr Settable via #new_value=

Returns:



# File 'lib/jamf/api/json_objects/extension_attribute_value.rb', line 59

Instance Method Details

#new_value=(new_val) ⇒ Object

setter for values. Usually called by Extendable#set_ext_attr



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/jamf/api/json_objects/extension_attribute_value.rb', line 92

def new_value=(new_val)

  # nil unsets the value
  unless new_val.nil?
    new_val =
      case @type
      when :integer
        Jamf::Validate.integer new_val, "Value for ext. attr. #{@name} must be an integer"
      when :date
        validate_date new_val
      else
        new_val.to_s
      end # case
  end # unless nil

  old_val = @value
  return if old_val == new_val
  @value = new_val
  note_unsaved_change(:value, old_val)
end

#to_jamfObject

the to_jamf in JSONObject would skip all these cuz they are read-only but we need them here.



116
117
118
119
120
121
122
123
124
# File 'lib/jamf/api/json_objects/extension_attribute_value.rb', line 116

def to_jamf
  return unless unsaved_changes?

  new_val = @type == :date ? @value.to_jamf : @value.to_s
  {
    id: @id,
    value: new_val
  }
end