Class: ScimPatchOperation
- Inherits:
-
Object
- Object
- ScimPatchOperation
- Defined in:
- app/libraries/scim_patch_operation.rb
Overview
Parse One of “Operations” in PATCH request
Instance Attribute Summary collapse
-
#op ⇒ Object
Returns the value of attribute op.
-
#path_scim ⇒ Object
Returns the value of attribute path_scim.
-
#path_sp ⇒ Object
Returns the value of attribute path_sp.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(op, path, value, mutable_attributes_schema) ⇒ ScimPatchOperation
constructor
A new instance of ScimPatchOperation.
- #save(model) ⇒ Object
Constructor Details
#initialize(op, path, value, mutable_attributes_schema) ⇒ ScimPatchOperation
Returns a new instance of ScimPatchOperation.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/libraries/scim_patch_operation.rb', line 7 def initialize(op, path, value, mutable_attributes_schema) # FIXME: Raise proper Error raise StandardError unless op.downcase.in? %w[add replace remove] # No path is not supported. # FIXME: Raise proper Error raise ScimRails::ExceptionHandler::UnsupportedPatchRequest if path.nil? raise ScimRails::ExceptionHandler::UnsupportedPatchRequest if value.nil? @op = op.downcase.to_sym @path_scim = path @path_sp = convert_path(path, mutable_attributes_schema) @value = convert_bool_if_string(value, @path_scim) end |
Instance Attribute Details
#op ⇒ Object
Returns the value of attribute op.
5 6 7 |
# File 'app/libraries/scim_patch_operation.rb', line 5 def op @op end |
#path_scim ⇒ Object
Returns the value of attribute path_scim.
5 6 7 |
# File 'app/libraries/scim_patch_operation.rb', line 5 def path_scim @path_scim end |
#path_sp ⇒ Object
Returns the value of attribute path_sp.
5 6 7 |
# File 'app/libraries/scim_patch_operation.rb', line 5 def path_sp @path_sp end |
#value ⇒ Object
Returns the value of attribute value.
5 6 7 |
# File 'app/libraries/scim_patch_operation.rb', line 5 def value @value end |
Instance Method Details
#save(model) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/libraries/scim_patch_operation.rb', line 22 def save(model) if @path_scim == 'members' # Only members are supported for value is an array update_member_ids = @value.map do |v| v[ScimRails.config.group_member_relation_schema.keys.first].to_s end current_member_ids = model .public_send(ScimRails.config.group_member_relation_attribute).map(&:to_s) case @op when :add member_ids = current_member_ids.concat(update_member_ids) when :replace member_ids = current_member_ids.concat(update_member_ids) when :remove member_ids = current_member_ids - update_member_ids end # Only the member addition process is saved by each ids model.public_send("#{ScimRails.config.group_member_relation_attribute}=", member_ids.uniq) return end case @op when :add, :replace model.attributes = { @path_sp => @value } when :remove model.attributes = { @path_sp => nil } end end |