Class: DeviseScim::Scim::PatchOperation

Inherits:
Object
  • Object
show all
Defined in:
lib/devise_scim/scim/patch_operation.rb

Constant Summary collapse

VALID_OPS =
%w[add remove replace].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operation:, path:, value: nil) ⇒ PatchOperation

Returns a new instance of PatchOperation.



24
25
26
27
28
29
# File 'lib/devise_scim/scim/patch_operation.rb', line 24

def initialize(operation:, path:, value: nil)
  @op = operation
  @raw_path = path
  @value = value
  parse_path(path)
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



10
11
12
# File 'lib/devise_scim/scim/patch_operation.rb', line 10

def attribute
  @attribute
end

#filterObject (readonly)

Returns the value of attribute filter.



10
11
12
# File 'lib/devise_scim/scim/patch_operation.rb', line 10

def filter
  @filter
end

#opObject (readonly)

Returns the value of attribute op.



10
11
12
# File 'lib/devise_scim/scim/patch_operation.rb', line 10

def op
  @op
end

#raw_pathObject (readonly)

Returns the value of attribute raw_path.



10
11
12
# File 'lib/devise_scim/scim/patch_operation.rb', line 10

def raw_path
  @raw_path
end

#sub_attributeObject (readonly)

Returns the value of attribute sub_attribute.



10
11
12
# File 'lib/devise_scim/scim/patch_operation.rb', line 10

def sub_attribute
  @sub_attribute
end

#valueObject (readonly)

Returns the value of attribute value.



10
11
12
# File 'lib/devise_scim/scim/patch_operation.rb', line 10

def value
  @value
end

Class Method Details

.parse(hash) ⇒ Object

Raises:

  • (ArgumentError)


12
13
14
15
16
17
# File 'lib/devise_scim/scim/patch_operation.rb', line 12

def self.parse(hash)
  operation = hash["op"]&.downcase
  raise ArgumentError, "Invalid op '#{hash["op"]}'; must be one of: #{VALID_OPS.join(", ")}" unless VALID_OPS.include?(operation)

  new(operation: operation, path: hash["path"], value: hash["value"])
end

.parse_request(body) ⇒ Object



19
20
21
22
# File 'lib/devise_scim/scim/patch_operation.rb', line 19

def self.parse_request(body)
  ops = body["Operations"] || body["operations"] || []
  ops.map { |op_hash| parse(op_hash) }
end