Class: Jamf::PeripheralType
- 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
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 ]
- 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
-
#fields ⇒ Array<Hash>
The definitions of the fields stored for this peripheral type.
-
#need_to_update ⇒ Boolean
included
from Updatable
readonly
Do we have unsaved changes?.
Instance Method Summary collapse
-
#append_field(**field) ⇒ void
Add a new field to the end of the field list.
-
#clone(new_name, api: nil, cnx: nil) ⇒ APIObject
included
from Creatable
make a clone of this API object, with a new name.
-
#delete_field(order) ⇒ void
Remove a field from the array of fields.
-
#initialize(**args) ⇒ PeripheralType
constructor
Initialize.
-
#insert_field(order, **field) ⇒ void
Add a new field to the middle of the fields Array.
-
#name=(newname) ⇒ void
included
from Updatable
Change the name of this item Remember to #update to push changes to the server.
-
#prepend_field(**field) ⇒ void
Add a new field to the beginning of the field list.
-
#set_field(order, **field) ⇒ void
Replace the details of one specific field.
Constructor Details
#initialize(**args) ⇒ PeripheralType
Initialize
73 74 75 76 77 78 79 80 |
# File 'lib/jamf/api/classic/api_objects/peripheral_type.rb', line 73 def initialize(**args) super @fields = [] return unless @init_data[:fields] @init_data[:fields].each { |f| @fields[f[:order]] = f } end |
Instance Attribute Details
#fields ⇒ Array<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.
114 115 116 |
# File 'lib/jamf/api/classic/api_objects/peripheral_type.rb', line 114 def fields @fields end |
#need_to_update ⇒ Boolean (readonly) Originally defined in module Updatable
Returns 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
162 163 164 165 166 167 |
# File 'lib/jamf/api/classic/api_objects/peripheral_type.rb', line 162 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
#delete_field(order) ⇒ void
This method returns an undefined value.
Remove a field from the array of fields.
206 207 208 209 210 211 212 213 |
# File 'lib/jamf/api/classic/api_objects/peripheral_type.rb', line 206 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.
192 193 194 195 196 197 |
# File 'lib/jamf/api/classic/api_objects/peripheral_type.rb', line 192 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.
#prepend_field(**field) ⇒ void
This method returns an undefined value.
Add a new field to the beginning of the field list
176 177 178 179 180 181 |
# File 'lib/jamf/api/classic/api_objects/peripheral_type.rb', line 176 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
147 148 149 150 151 152 153 |
# File 'lib/jamf/api/classic/api_objects/peripheral_type.rb', line 147 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 |