Class: Appsignal::Utils::Data Private

Inherits:
Object
  • Object
show all
Defined in:
lib/appsignal/utils/data.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Class Method Summary collapse

Class Method Details

.generate(body) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



8
9
10
11
12
13
14
15
16
# File 'lib/appsignal/utils/data.rb', line 8

def generate(body)
  if body.is_a?(Hash)
    map_hash(body)
  elsif body.is_a?(Array)
    map_array(body)
  else
    raise TypeError, "Body of type #{body.class} should be a Hash or Array"
  end
end

.map_array(array_value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/appsignal/utils/data.rb', line 50

def map_array(array_value)
  array = Appsignal::Extension.data_array_new
  array_value.each do |value|
    case value
    when String
      array.append_string(value)
    when Integer
      # An Integer too big for C-lang longs to fit
      bigint = 1 << 63
      if value >= bigint
        array.append_string("bigint:#{value}")
      else
        array.append_integer(value)
      end
    when Float
      array.append_float(value)
    when TrueClass, FalseClass
      array.append_boolean(value)
    when NilClass
      array.append_nil
    when Hash
      array.append_data(map_hash(value))
    when Array
      array.append_data(map_array(value))
    else
      array.append_string(value.to_s)
    end
  end
  array
end

.map_hash(hash_value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/appsignal/utils/data.rb', line 18

def map_hash(hash_value)
  map = Appsignal::Extension.data_map_new
  hash_value.each do |key, value|
    key = key.to_s
    case value
    when String
      map.set_string(key, value)
    when Integer
      # An Integer too big for C-lang longs to fit
      bigint = 1 << 63
      if value >= bigint
        map.set_string(key, "bigint:#{value}")
      else
        map.set_integer(key, value)
      end
    when Float
      map.set_float(key, value)
    when TrueClass, FalseClass
      map.set_boolean(key, value)
    when NilClass
      map.set_nil(key)
    when Hash
      map.set_data(key, map_hash(value))
    when Array
      map.set_data(key, map_array(value))
    else
      map.set_string(key, value.to_s)
    end
  end
  map
end