Module: Jamf::JPAPIResource::ClassMethods

Included in:
CollectionResource::ClassMethods
Defined in:
lib/jamf/api/jamf_pro/mixins/jpapi_resource.rb

Overview

Class Methods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(extender) ⇒ Object



49
50
51
# File 'lib/jamf/api/jamf_pro/mixins/jpapi_resource.rb', line 49

def self.extended(extender)
  Jamf.load_msg "--> #{extender} is extending Jamf::JPAPIResource::ClassMethods"
end

Instance Method Details

#new(**data) ⇒ Object

Disallow direct use of ruby’s .new class method for creating instances. Require use of a method in NEW_CALLERS, or the data must include :instantiate_me

WARNING: do not abuse :instantiate_me, it exists so we don’t constantly have to update NEW_CALLERS



66
67
68
69
70
71
72
73
74
75
# File 'lib/jamf/api/jamf_pro/mixins/jpapi_resource.rb', line 66

def new(**data)
  calling_method = caller_locations(1..1).first.label
  unless NEW_CALLERS.include? calling_method || data[:instantiate_me]
    raise Jamf::UnsupportedError, 'Use .fetch, .create, or .all(instantiate:true) to instantiate Jamf::JPAPIResource objects'
  end

  data.delete :instantiate_me

  super(**data)
end

#which_apiObject

Indicate that this class comes from the Jamf Pro API. The same method exists in APIObject to indicate coming from Classic



55
56
57
# File 'lib/jamf/api/jamf_pro/mixins/jpapi_resource.rb', line 55

def which_api
  :jamf_pro
end