Class: LogSnag::Insight

Inherits:
EventBase show all
Defined in:
lib/logsnag/insight.rb

Overview

Constructs and validates an “insight” object

Constant Summary collapse

REQUIRED_KEYS =
%i[project title value].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from EventBase

#to_json

Constructor Details

#initialize(data, config, mutate: false) ⇒ LogSnag::Insight

Creates a new Insight object. The data hash MUST include the following keys:

- :title [String] The title of the insight.
- :value [String,Numeric] The numerical value of the insight.

The data hash MAY include the following keys:

- :icon [String] The icon to be displayed with the insight.

Parameters:

  • data (Hash)

    The data to be sent to LogSnag.

  • config (LogSnag::Configuration)

    The configuration object.

  • mutate (Boolean) (defaults to: false)

    Whether or not to mutate the data hash.

Raises:

  • (ArgumentError)

    If the hash is missing required keys, has invalid keys, or has values of incorrect types.

See Also:



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/logsnag/insight.rb', line 25

def initialize(data, config, mutate: false)
  super(data, config)

  append_required_fields!

  if mutate
    validate_mutation_data
  else
    validate_data
  end
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



11
12
13
# File 'lib/logsnag/insight.rb', line 11

def config
  @config
end

#dataObject (readonly)

Returns the value of attribute data.



11
12
13
# File 'lib/logsnag/insight.rb', line 11

def data
  @data
end