Class: LogSnag::EventBase Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/logsnag/event_base.rb

Overview

This class is abstract.

Subclass and override #data and #config to implement.

Provides a base class for LogSnag events. Ensures that the data hash is valid and that the configuration object is present.

Returns:

Raises:

  • (ArgumentError)

    If the hash is missing required keys or contains invalid keys.

Direct Known Subclasses

Identify, Insight, Log

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, config) ⇒ EventBase

Returns a new instance of EventBase.

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
21
22
23
24
# File 'lib/logsnag/event_base.rb', line 14

def initialize(data, config)
  @data = data
  @config = config

  raise ArgumentError, "`data` must be a Hash" unless data.is_a?(Hash)

  return if config.is_a?(LogSnag::Configuration)

  raise ArgumentError,
        "LogSnag::Configuration not found. Did you call LogSnag.configure?"
end

Instance Attribute Details

#configLogSnag::Configuration (readonly)

The configuration object.

Returns:



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

def config
  @config
end

#dataHash (readonly)

The data to be sent to LogSnag.

Returns:

  • (Hash)

    the current value of data



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

def data
  @data
end

Instance Method Details

#to_json(*_args) ⇒ Object



26
27
28
# File 'lib/logsnag/event_base.rb', line 26

def to_json(*_args)
  data.to_json
end