Module: Jamf::Lockable

Defined in:
lib/jamf/api/jamf_pro/mixins/lockable.rb

Overview

Classes mixing this in have a ‘versionLock’ attribute and implement ‘Optimistic Locking’

https://stackoverflow.com/questions/129329/optimistic-vs-pessimistic-locking/129397#129397

When the object is saved, the versionLock is sent back with the data and if it doesn’t match whats on the server, then the object has been updated from elsewhere since we fetched it, and a 409 Conflict error is raised with the reason OPTIMISTIC_LOCK_FAILED.

If that happens, the save doesnt happen, the object must be re-fetched, and the user can try again.

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#versionLockObject (readonly)

module class methods



46
47
48
# File 'lib/jamf/api/jamf_pro/mixins/lockable.rb', line 46

def versionLock
  @versionLock
end

Class Method Details

.included(includer) ⇒ Object

when this module is included, also extend our Class Methods



27
28
29
30
# File 'lib/jamf/api/jamf_pro/mixins/lockable.rb', line 27

def self.included(includer)
  Jamf.load_msg "--> #{includer} is including Jamf::Lockable"
  includer.extend(ClassMethods)
end

Instance Method Details

#initialize(**data) ⇒ Object



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

def initialize(**data)
  @versionLock = data[:versionLock]
  super(**data)
end

#lockable?Boolean



59
60
61
# File 'lib/jamf/api/jamf_pro/mixins/lockable.rb', line 59

def lockable?
  self.class.lockable?
end

#to_jamfObject



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

def to_jamf
  data = super
  data[:versionLock] = @versionLock
  data
end