Module: JSSWebHooks::EventObjects

Defined in:
lib/jss/webhooks/event_objects.rb

Overview

Event Objects are JSON structures that come from the JSS with every webhook event. They represent the object that was affected by the event. For example, A ComputerAdded event affects a computer, and a RestAPIOperation event affects a REST API object.

Since these Event Objects are mostly just short-lived static data they don’t need to be represented full-blown Classes, but they would be nicer to work with if they weren’t just Hashes.

Ruby’s Struct class provides a handy way to create something that’s more than a Hash but less than a full Class. Unfortuantely, Struct- derived classes are fully mutable, and require positional parameters when creating instances.

The ImmutableStruct class, provided by the immutable-struct gem, (github.com/stitchfix/immutable-struct) creates classes whose instances have immutable attributes, but allow (nay, require) named parameters when creating instances.

This module dynamically creates ImmutableStruct classes for the various Event Objects that come with each webhook event. Each Event Objects class is defined in the @object_definitions Hash, which is accessible via the JSSWebHooks::EventObjects::object_definitions method.

Each object is defined in that Hash thus:

Key:  Symbol, the name of the object e.g. :computer
Value: Hash, the attributes and other data for created the object's Class

The value hash has these keys:

:class_name => String, the name of the ImmutableStruct Class for this
   object, e.g. "Computer"
:attributes => Array[<Symbol>], The instance-attributes for the Class, to
   be passed in as the keys of a hash when creating an instance.
:methods => Array[<Hash>], if any methods are needed for the Class, other
   than the default getters for the attributes, each Hash in this array
   defines one. The :name key contains a symbol, the name of the method,
   and the :proc key contains a Proc object, the method code. See
   JSSWebHooks::EventObjects.object_definitions[:patch_software_title_update]
   for an example.

Class Method Summary collapse

Class Method Details

.object_definitionsHash

Access to the Module-instance var @object_definitions

Returns:

  • (Hash)

    the @object_definitions Hash



80
81
82
# File 'lib/jss/webhooks/event_objects.rb', line 80

def self.object_definitions
  @object_definitions
end