Class: ScimPatch
- Inherits:
-
Object
- Object
- ScimPatch
- Defined in:
- app/libraries/scim_patch.rb
Overview
Parse PATCH request
Instance Attribute Summary collapse
-
#operations ⇒ Object
Returns the value of attribute operations.
Instance Method Summary collapse
- #create_operation(resource_type, op, path, value) ⇒ Object
-
#initialize(params, resource_type) ⇒ ScimPatch
constructor
A new instance of ScimPatch.
- #save(model) ⇒ Object
Constructor Details
#initialize(params, resource_type) ⇒ ScimPatch
Returns a new instance of ScimPatch.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/libraries/scim_patch.rb', line 7 def initialize(params, resource_type) if params['schemas'] != ['urn:ietf:params:scim:api:messages:2.0:PatchOp'] || params['Operations'].nil? raise Scimaenaga::ExceptionHandler::UnsupportedPatchRequest end # complex-value(Hash) operation is converted to multiple single-value operations converted_operations = ScimPatchOperationConverter.convert(params['Operations']) @operations = converted_operations.map do |o| create_operation(resource_type, o['op'], o['path'], o['value']) end end |
Instance Attribute Details
#operations ⇒ Object
Returns the value of attribute operations.
5 6 7 |
# File 'app/libraries/scim_patch.rb', line 5 def operations @operations end |
Instance Method Details
#create_operation(resource_type, op, path, value) ⇒ Object
20 21 22 23 24 25 26 |
# File 'app/libraries/scim_patch.rb', line 20 def create_operation(resource_type, op, path, value) if resource_type == :user ScimPatchOperationUser.new(op, path, value) else ScimPatchOperationGroup.new(op, path, value) end end |
#save(model) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/libraries/scim_patch.rb', line 28 def save(model) model.transaction do @operations.each do |operation| operation.save(model) end model.save! if model.changed? end rescue ActiveRecord::RecordNotFound raise rescue StandardError => e raise Scimaenaga::ExceptionHandler::UnsupportedPatchRequest, e. end |