Class: Contrast::Agent::Assess::ContrastObject

Inherits:
Object
  • Object
show all
Defined in:
lib/contrast/agent/assess/contrast_object.rb

Overview

This class is a convenient holder of our version of an Object. It creates a String version of the Object from the original provided and keeps reference to the original’s Tags, letting us determine if it was tracked when we try to report to TeamServer.

TODO: RUBY-1083 determine if this is expensive and/or worth not storing these values directly on ContrastEvent

and passing them around. Args probably make the argument for wrapping them b/c otherwise we'll have to keep
two arrays in synch or make an array of arrays, at which point, we may as well make this.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ ContrastObject

Capture the details about the object which we need to render it in TeamServer.

Parameters:

  • object (Object, nil)

    the thing to keep a Contrast String of



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/contrast/agent/assess/contrast_object.rb', line 32

def initialize object
  if object
    @object = Contrast::Utils::ClassUtil.to_contrast_string(object)
    @tracked_object_id = object.__id__
    @object_type = object.cs__class.cs__name
    @tags = Contrast::Agent::Assess::Tracker.properties(object)&.get_tags
  else
    @object = Contrast::Utils::ObjectShare::NIL_STRING
    @tracked_object_id = nil.__id__
    @object_type = nil.cs__class.cs__name
  end
end

Instance Attribute Details

#objectString (readonly)

Returns the Contrast String representation of the Object.

Returns:

  • (String)

    the Contrast String representation of the Object.



20
21
22
# File 'lib/contrast/agent/assess/contrast_object.rb', line 20

def object
  @object
end

#object_typeString (readonly)

Returns the name of the Class/Module of the Object.

Returns:

  • (String)

    the name of the Class/Module of the Object.



24
25
26
# File 'lib/contrast/agent/assess/contrast_object.rb', line 24

def object_type
  @object_type
end

#tagsHash<Contrast::Agent::Assess::Tag> (readonly)

Returns the tags on the original Object.

Returns:



26
27
28
# File 'lib/contrast/agent/assess/contrast_object.rb', line 26

def tags
  @tags
end

#tracked_object_idInteger (readonly)

Returns the __id__ of the original Object.

Returns:

  • (Integer)

    the __id__ of the original Object.



22
23
24
# File 'lib/contrast/agent/assess/contrast_object.rb', line 22

def tracked_object_id
  @tracked_object_id
end

Instance Method Details

#tracked?Boolean

Is the object this represents tracked or not?

Returns:

  • (Boolean)


48
49
50
# File 'lib/contrast/agent/assess/contrast_object.rb', line 48

def tracked?
  !!tags&.any?
end