Class: ScoutApm::Utils::MarshalLogging

Inherits:
Object
  • Object
show all
Defined in:
lib/scout_apm/utils/marshal_logging.rb

Instance Method Summary collapse

Constructor Details

#initialize(base_obj) ⇒ MarshalLogging

Returns a new instance of MarshalLogging.



25
26
27
# File 'lib/scout_apm/utils/marshal_logging.rb', line 25

def initialize(base_obj)
  @base_obj = base_obj
end

Instance Method Details

#diveObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
# File 'lib/scout_apm/utils/marshal_logging.rb', line 29

def dive
  to_investigate = [InstanceVar.new('Root', @base_obj, nil)]
  max_to_check = 10000
  checked = 0

  while (var = to_investigate.shift)
    checked += 1 
    if checked > max_to_check
      return "Limiting Checks (max = #{max_to_check})"
    end

    obj = var.obj

    if offending_hash?(obj)
      return "Found undumpable object: #{var.history}"
    end

    if !dumps?(obj)
      if obj.is_a? Hash
        keys = obj.keys
        keys.each do |key|
          to_investigate.push(
            InstanceVar.new(key.to_s, obj[key], var)
          )
        end
      elsif obj.is_a? Array
        obj.each_with_index do |value, idx|
          to_investigate.push(
            InstanceVar.new("Index #{idx}", value, var)
          )
        end
      else
        symbols = obj.instance_variables
        if !symbols.any?
          return "Found undumpable object: #{var.history}"
        end

        symbols.each do |sym|
          to_investigate.push(
            InstanceVar.new(sym, obj.instance_variable_get(sym), var)
          )
        end
      end
    end
  end

  true
end

#dumps?(obj) ⇒ Boolean

Returns:

  • (Boolean)


78
79
80
81
82
83
# File 'lib/scout_apm/utils/marshal_logging.rb', line 78

def dumps?(obj)
  Marshal.dump(obj)
  true
rescue TypeError
  false
end

#offending_hash?(obj) ⇒ Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/scout_apm/utils/marshal_logging.rb', line 85

def offending_hash?(obj)
  obj.is_a?(Hash) && !obj.default_proc.nil?
end