Class: Contrast::Agent::Reporting::ReportableHash

Inherits:
Object
  • Object
show all
Includes:
Components::Logger::InstanceMethods
Defined in:
lib/contrast/agent/reporting/reporting_events/reportable_hash.rb

Overview

A class supporting all to_controlled_hash reporting methods. All errors raised during validation will be handled here.

Instance Method Summary collapse

Methods included from Components::Logger::InstanceMethods

#cef_logger, #logger

Instance Method Details

#event_jsonObject

Helper method to get json representation of event objects and handle errors.

@return [String, nil] - JSON


30
31
32
33
34
# File 'lib/contrast/agent/reporting/reporting_events/reportable_hash.rb', line 30

def event_json
  return unless valid?

  to_controlled_hash.to_json
end

#to_controlled_hashHash?

Convert the instance variables on the class, and other information, into the identifiers required for TeamServer to process the JSON form of this message.

Returns:

Raises:

  • (ArgumentError)


19
20
21
22
# File 'lib/contrast/agent/reporting/reporting_events/reportable_hash.rb', line 19

def to_controlled_hash
  validate
  {}
end

#valid?Boolean

Check before building the json if the event is valid. This will also log the error if the event is invalid. This will save some object creation in the reporter in the case of an invalid event, and will stop the reporting of the event.

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/contrast/agent/reporting/reporting_events/reportable_hash.rb', line 44

def valid?
  @_valid ||= begin
    validate
    # Some deeply nested validations only happens on
    # the to_controlled_hash method, so we need to
    # invoke it.
    to_controlled_hash
    true
  rescue ArgumentError => e
    handle_validation_error(e)
    false
  end
end

#validateObject

Raises:

  • (ArgumentError)


25
# File 'lib/contrast/agent/reporting/reporting_events/reportable_hash.rb', line 25

def validate; end