Module: Appsignal::Hooks::Helpers

Included in:
DelayedJobPlugin, SidekiqPlugin, Integrations::ResqueActiveJobPlugin
Defined in:
lib/appsignal/hooks.rb

Instance Method Summary collapse

Instance Method Details

#extract_value(object_or_hash, field, default_value = nil, convert_to_s = false) ⇒ Object


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/appsignal/hooks.rb', line 62

def extract_value(object_or_hash, field, default_value=nil, convert_to_s=false)
  value = if object_or_hash.respond_to?(:[])
    begin
      object_or_hash[field]
    rescue NameError
      nil
    end
  elsif object_or_hash.respond_to?(field)
    object_or_hash.send(field)
  end || default_value
  if convert_to_s
    value.to_s
  else
    value
  end
end

#format_args(args) ⇒ Object


79
80
81
82
83
# File 'lib/appsignal/hooks.rb', line 79

def format_args(args)
  args.map do |arg|
    truncate(string_or_inspect(arg))
  end
end

#string_or_inspect(string_or_other) ⇒ Object


50
51
52
53
54
55
56
# File 'lib/appsignal/hooks.rb', line 50

def string_or_inspect(string_or_other)
  if string_or_other.is_a?(String)
    string_or_other
  else
    string_or_other.inspect
  end
end

#truncate(text) ⇒ Object


58
59
60
# File 'lib/appsignal/hooks.rb', line 58

def truncate(text)
  text.size > 200 ? "#{text[0...197]}..." : text
end