Class: Courier::Users::Tokens::PatchOperation

Inherits:
Object
  • Object
show all
Defined in:
lib/trycourier/users/tokens/types/patch_operation.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(op:, path:, value: nil, additional_properties: nil) ⇒ Users::Tokens::PatchOperation

Parameters:

  • op (String)

    The operation to perform.

  • path (String)

    The JSON path specifying the part of the profile to operate on.

  • value (String) (defaults to: nil)

    The value for the operation.

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



16
17
18
19
20
21
22
23
24
25
# File 'lib/trycourier/users/tokens/types/patch_operation.rb', line 16

def initialize(op:, path:, value: nil, additional_properties: nil)
  # @type [String] The operation to perform.
  @op = op
  # @type [String] The JSON path specifying the part of the profile to operate on.
  @path = path
  # @type [String] The value for the operation.
  @value = value
  # @type [OpenStruct] Additional properties unmapped to the current class definition
  @additional_properties = additional_properties
end

Instance Attribute Details

#additional_propertiesObject (readonly)

Returns the value of attribute additional_properties.



9
10
11
# File 'lib/trycourier/users/tokens/types/patch_operation.rb', line 9

def additional_properties
  @additional_properties
end

#opObject (readonly)

Returns the value of attribute op.



9
10
11
# File 'lib/trycourier/users/tokens/types/patch_operation.rb', line 9

def op
  @op
end

#pathObject (readonly)

Returns the value of attribute path.



9
10
11
# File 'lib/trycourier/users/tokens/types/patch_operation.rb', line 9

def path
  @path
end

#valueObject (readonly)

Returns the value of attribute value.



9
10
11
# File 'lib/trycourier/users/tokens/types/patch_operation.rb', line 9

def value
  @value
end

Class Method Details

.from_json(json_object:) ⇒ Users::Tokens::PatchOperation

Deserialize a JSON object to an instance of PatchOperation

Parameters:

  • json_object (JSON)

Returns:



31
32
33
34
35
36
37
38
# File 'lib/trycourier/users/tokens/types/patch_operation.rb', line 31

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  JSON.parse(json_object)
  op = struct.op
  path = struct.path
  value = struct.value
  new(op: op, path: path, value: value, additional_properties: struct)
end

.validate_raw(obj:) ⇒ Void

Leveraged for Union-type generation, validate_raw attempts to parse the given hash and check each fields type against the current object’s property definitions.

Parameters:

  • obj (Object)

Returns:

  • (Void)


51
52
53
54
55
# File 'lib/trycourier/users/tokens/types/patch_operation.rb', line 51

def self.validate_raw(obj:)
  obj.op.is_a?(String) != false || raise("Passed value for field obj.op is not the expected type, validation failed.")
  obj.path.is_a?(String) != false || raise("Passed value for field obj.path is not the expected type, validation failed.")
  obj.value&.is_a?(String) != false || raise("Passed value for field obj.value is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ JSON

Serialize an instance of PatchOperation to a JSON object

Returns:

  • (JSON)


43
44
45
# File 'lib/trycourier/users/tokens/types/patch_operation.rb', line 43

def to_json(*_args)
  { "op": @op, "path": @path, "value": @value }.to_json
end