Class: Jamf::PeripheralType

Inherits:
APIObject show all
Includes:
Creatable, Updatable
Defined in:
lib/jamf/api/classic/api_objects/peripheral_type.rb

Overview

A peripheral_type in the JSS.

A PeripheralType (as opposed to an individual Peripheral) is just an id, a name, and an Array of Hashes describing the fields of data to be stored for peripherals of this type.

See #fields for a desciption of how field definitions are stored.

For manipulating the fields, see #fields=, #set_field, #append_field, #prepend_field, #insert_field, and #delete_field

See Also:

Constant Summary collapse

RSRC_BASE =

The base for REST resources of this class

'peripheraltypes'
RSRC_LIST_KEY =

the hash key used for the JSON list output of all objects in the JSS

:peripheral_types
RSRC_OBJECT_KEY =

The hash key used for the JSON object output. It’s also used in various error messages

:peripheral_type
FIELD_TYPES =

field types can be one of these, either String or Symbol

%i[text menu]
OBJECT_HISTORY_OBJECT_TYPE =

the object type for this object in the object history table. See APIObject#add_object_history_entry

11

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ PeripheralType

Initialize



91
92
93
94
95
96
97
98
99
# File 'lib/jamf/api/classic/api_objects/peripheral_type.rb', line 91

def initialize(**args)
  super

  @fields = []
  return unless @init_data[:fields]

  @init_data[:fields].each { |f| @fields[f[:order]] = f }
  
end

Instance Attribute Details

#fieldsArray<Hash>

The definitions of the fields stored for this peripheral type.

Each Hash defines a field of data to store. The keys are:

  • :name, String, the name of the field

  • :type, String or Symbol, the kind of data to be stored in the field, either :text or :menu

  • :choices, Array of Strings - if type is :menu, these are the menu choices.

  • :order, the one-based index of this field amongst it’s peers.

Since Arrays are zero-based, and the field order is one-based, keeping a nil at the front of the Array will keep the :order number in sync with the Array index of each field definition. This is done automatically by the field-editing methods: #fields=, #set_field, #append_field, #prepend_field, #insert_field, and #delete_field.

So the Array from the API comes like this:

[ {:type=>"text", :order=>1, :choices=>[], :name=>"make"},
  {:type=>"text", :order=>2, :choices=>[], :name=>"model"},
  {:type=>"text", :order=>3, :choices=>[], :name=>"family"},
  {:type=>"text", :order=>4, :choices=>[], :name=>"serialnum"} ]

But will be stored in a PeripheralType instance like this:

[ nil,
  {:type=>"text", :order=>1, :choices=>[], :name=>"make"},
  {:type=>"text", :order=>2, :choices=>[], :name=>"model"},
  {:type=>"text", :order=>3, :choices=>[], :name=>"family"},
  {:type=>"text", :order=>4, :choices=>[], :name=>"serialnum"} ]

therefore

myPerifType.fields[2]

will get you the second field, which has :order => 2.

Returns:



133
134
135
# File 'lib/jamf/api/classic/api_objects/peripheral_type.rb', line 133

def fields
  @fields
end

#need_to_updateBoolean (readonly) Originally defined in module Updatable

Returns do we have unsaved changes?.

Returns:

  • (Boolean)

    do we have unsaved changes?

Instance Method Details

#append_field(**field) ⇒ void

This method returns an undefined value.

Add a new field to the end of the field list

Parameters:

  • field (Hash)

    the new field data



181
182
183
184
185
186
# File 'lib/jamf/api/classic/api_objects/peripheral_type.rb', line 181

def append_field(**field)
  field_ok? field
  @fields << field
  order_fields
  @need_to_update = true
end

#clone(new_name, api: nil, cnx: nil) ⇒ APIObject Originally defined in module Creatable

make a clone of this API object, with a new name. The class must be creatable

Parameters:

  • name (String)

    the name for the new object

  • cnx (Jamf::Connection) (defaults to: nil)

    the API in which to create the object Defaults to the API used to instantiate this object

Returns:

  • (APIObject)

    An unsaved clone of this APIObject with the given name

Raises:

#delete_field(order) ⇒ void

This method returns an undefined value.

Remove a field from the array of fields.

Parameters:

  • order (Integer)

    which field to remove?

Raises:



225
226
227
228
229
230
231
232
233
# File 'lib/jamf/api/classic/api_objects/peripheral_type.rb', line 225

def delete_field(order)
  return unless @fields[order]
  raise Jamf::MissingDataError, "Fields can't be empty" if @fields.count == 1

  @fields.delete_at index
  order_fields
  @need_to_update = true
  
end

#insert_field(order, **field) ⇒ void

This method returns an undefined value.

Add a new field to the middle of the fields Array.

Parameters:

  • order (Integer)

    where does the new field go?

  • field (Hash)

    the new field data



211
212
213
214
215
216
# File 'lib/jamf/api/classic/api_objects/peripheral_type.rb', line 211

def insert_field(order, **field)
  field_ok? field
  @fields.insert((order - 1), field)
  order_fields
  @need_to_update = true
end

#name=(newname) ⇒ void Originally defined in module Updatable

This method returns an undefined value.

Change the name of this item Remember to #update to push changes to the server.

Parameters:

  • newname (String)

    the new name

Raises:

#prepend_field(**field) ⇒ void

This method returns an undefined value.

Add a new field to the beginning of the field list

Parameters:

  • field (Hash)

    the new field data



195
196
197
198
199
200
# File 'lib/jamf/api/classic/api_objects/peripheral_type.rb', line 195

def prepend_field(**field)
  field_ok? field
  @fields.unshift field
  order_fields
  @need_to_update = true
end

#set_field(order, **field) ⇒ void

This method returns an undefined value.

Replace the details of one specific field.

The order must already exist. Otherwise use #append_field, #prepend_field, or #insert_field

Parameters:

  • order (Integer)

    which field are we replacing?

  • field (Hash)

    the new field data

Raises:



166
167
168
169
170
171
172
# File 'lib/jamf/api/classic/api_objects/peripheral_type.rb', line 166

def set_field(order, **field)
  raise Jamf::NoSuchItemError, "No field with number '#{order}'. Use #append_field, #prepend_field, or #insert_field" unless @fields[order]

  field_ok? field
  @fields[order] = field
  @need_to_update = true
end