Class: ScimPatchOperationConverter

Inherits:
Object
  • Object
show all
Defined in:
app/libraries/scim_patch_operation_converter.rb

Overview

  1. Convert each multi-value operation to single-value operations.

  2. Fix wrong “value”.

  3. convert “op” to lower case

About #1 to handle request pattern A and B in the same way, convert complex-value to path + single-value

Typical request is path_base = nil and value = complex-value: {

"op": "replace",
"value": {
    "displayName": "Taro Suzuki",
    "name.givenName": "taro"
}

}

This request is converted to: [

{
  "op": "replace",
  "path": "displayName",
  "value": "Taro Suzuki",
}
{
  "op": "replace",
  "path": "name.givenName",
  "value": "taro"
}

]

Class Method Summary collapse

Class Method Details

.convert(operations) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/libraries/scim_patch_operation_converter.rb', line 35

def convert(operations)
  operations.each_with_object([]) do |o, result|
    value = o['value']
    value = value.permit!.to_h if value.instance_of?(ActionController::Parameters)

    if value.is_a?(Hash)
      converted_operations = convert_to_single_value_operations(o['op'], o['path'],
                                                                value)
      result.concat(converted_operations)
      next
    end

    result << fix_operation_format(o['op'], o['path'], value)
  end
end