Class: OpenObserve::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/openobserve/record.rb

Overview

Base for the gem's value objects (Alert, Destination, Template, Incident, Stream, Hit). A thin, read-only view over a response hash: string keys are preserved and the full payload stays reachable through #raw / #[], so nothing the API returned is ever hidden by the wrapper.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ Record

Returns a new instance of Record.



19
20
21
# File 'lib/openobserve/record.rb', line 19

def initialize(raw)
  @raw = raw || {}
end

Instance Attribute Details

#rawHash (readonly)

Returns the payload.

Returns:

  • (Hash)

    the payload



10
11
12
# File 'lib/openobserve/record.rb', line 10

def raw
  @raw
end

Class Method Details

.from(hash) ⇒ OpenObserve::Record

Build from a raw parsed response hash.

Parameters:

  • hash (Hash, nil)

Returns:



15
16
17
# File 'lib/openobserve/record.rb', line 15

def self.from(hash)
  new(hash)
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?

Two records are equal when they are the same class and wrap the same payload.

Parameters:

  • other (Object)

Returns:

  • (Boolean)


37
38
39
# File 'lib/openobserve/record.rb', line 37

def ==(other)
  other.instance_of?(self.class) && raw == other.raw
end

#[](key) ⇒ Object

Read any field by its OpenObserve key.

Parameters:

  • key (String, Symbol)


25
26
27
# File 'lib/openobserve/record.rb', line 25

def [](key)
  raw[key.to_s]
end

#hashInteger

Returns a hash consistent with #==, so records key Hashes / Sets correctly.

Returns:

  • (Integer)

    a hash consistent with #==, so records key Hashes / Sets correctly



43
44
45
# File 'lib/openobserve/record.rb', line 43

def hash
  [self.class, raw].hash
end

#idString, ...

Returns the object id.

Returns:

  • (String, Integer, nil)

    the object id



30
31
32
# File 'lib/openobserve/record.rb', line 30

def id
  self['id']
end

#to_hHash

Returns the payload.

Returns:

  • (Hash)

    the payload



48
49
50
# File 'lib/openobserve/record.rb', line 48

def to_h
  raw
end