Class: Intrinsic::DetectionObject

Inherits:
Object
  • Object
show all
Defined in:
lib/intrinsic/types/detection_object.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object:, event_id:, status:, id: nil, violates_policy: nil, violated_policies: nil, explanation: nil, additional_properties: nil) ⇒ DetectionObject

Parameters:

  • object (String)
  • id (String) (defaults to: nil)

    ID of the detection

  • event_id (String)

    ID of the event associated with a detection

  • status (DETECTION_OBJECT_STATUS)
  • violates_policy (Boolean) (defaults to: nil)

    Whether any policies were violated

  • violated_policies (Array<ViolatedPolicyObject>) (defaults to: nil)
  • explanation (String) (defaults to: nil)

    Explanation of the detection outcome

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/intrinsic/types/detection_object.rb', line 21

def initialize(object:, event_id:, status:, id: nil, violates_policy: nil, violated_policies: nil,
               explanation: nil, additional_properties: nil)
  # @type [String]
  @object = object
  # @type [String] ID of the detection
  @id = id
  # @type [String] ID of the event associated with a detection
  @event_id = event_id
  # @type [DETECTION_OBJECT_STATUS]
  @status = status
  # @type [Boolean] Whether any policies were violated
  @violates_policy = violates_policy
  # @type [Array<ViolatedPolicyObject>]
  @violated_policies = violated_policies
  # @type [String] Explanation of the detection outcome
  @explanation = explanation
  # @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/intrinsic/types/detection_object.rb', line 9

def additional_properties
  @additional_properties
end

#event_idObject (readonly)

Returns the value of attribute event_id.



9
10
11
# File 'lib/intrinsic/types/detection_object.rb', line 9

def event_id
  @event_id
end

#explanationObject (readonly)

Returns the value of attribute explanation.



9
10
11
# File 'lib/intrinsic/types/detection_object.rb', line 9

def explanation
  @explanation
end

#idObject (readonly)

Returns the value of attribute id.



9
10
11
# File 'lib/intrinsic/types/detection_object.rb', line 9

def id
  @id
end

#objectObject (readonly)

Returns the value of attribute object.



9
10
11
# File 'lib/intrinsic/types/detection_object.rb', line 9

def object
  @object
end

#statusObject (readonly)

Returns the value of attribute status.



9
10
11
# File 'lib/intrinsic/types/detection_object.rb', line 9

def status
  @status
end

#violated_policiesObject (readonly)

Returns the value of attribute violated_policies.



9
10
11
# File 'lib/intrinsic/types/detection_object.rb', line 9

def violated_policies
  @violated_policies
end

#violates_policyObject (readonly)

Returns the value of attribute violates_policy.



9
10
11
# File 'lib/intrinsic/types/detection_object.rb', line 9

def violates_policy
  @violates_policy
end

Class Method Details

.from_json(json_object:) ⇒ DetectionObject

Deserialize a JSON object to an instance of DetectionObject

Parameters:

  • json_object (JSON)

Returns:



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/intrinsic/types/detection_object.rb', line 45

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  object = struct.object
  id = struct.id
  event_id = struct.event_id
  status = DETECTION_OBJECT_STATUS.key(parsed_json["status"]) || parsed_json["status"]
  violates_policy = struct.violates_policy
  violated_policies = parsed_json["violated_policies"]&.map do |v|
    v = v.to_json
    ViolatedPolicyObject.from_json(json_object: v)
  end
  explanation = struct.explanation
  new(object: object, id: id, event_id: event_id, status: status, violates_policy: violates_policy,
      violated_policies: violated_policies, explanation: explanation, 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)


81
82
83
84
85
86
87
88
89
# File 'lib/intrinsic/types/detection_object.rb', line 81

def self.validate_raw(obj:)
  obj.object.is_a?(String) != false || raise("Passed value for field obj.object is not the expected type, validation failed.")
  obj.id&.is_a?(String) != false || raise("Passed value for field obj.id is not the expected type, validation failed.")
  obj.event_id.is_a?(String) != false || raise("Passed value for field obj.event_id is not the expected type, validation failed.")
  obj.status.is_a?(DETECTION_OBJECT_STATUS) != false || raise("Passed value for field obj.status is not the expected type, validation failed.")
  obj.violates_policy&.is_a?(Boolean) != false || raise("Passed value for field obj.violates_policy is not the expected type, validation failed.")
  obj.violated_policies&.is_a?(Array) != false || raise("Passed value for field obj.violated_policies is not the expected type, validation failed.")
  obj.explanation&.is_a?(String) != false || raise("Passed value for field obj.explanation is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ JSON

Serialize an instance of DetectionObject to a JSON object

Returns:

  • (JSON)


65
66
67
68
69
70
71
72
73
74
75
# File 'lib/intrinsic/types/detection_object.rb', line 65

def to_json(*_args)
  {
    "object": @object,
    "id": @id,
    "event_id": @event_id,
    "status": DETECTION_OBJECT_STATUS[@status] || @status,
    "violates_policy": @violates_policy,
    "violated_policies": @violated_policies,
    "explanation": @explanation
  }.to_json
end