Module: Appsignal::Hooks::Helpers
- Included in:
- DelayedJobPlugin, SidekiqPlugin, Integrations::ResqueActiveJobPlugin
- Defined in:
- lib/appsignal/hooks.rb
Instance Method Summary collapse
- #extract_value(object_or_hash, field, default_value = nil, convert_to_s = false) ⇒ Object
- #format_args(args) ⇒ Object
- #string_or_inspect(string_or_other) ⇒ Object
- #truncate(text) ⇒ Object
Instance Method Details
#extract_value(object_or_hash, field, default_value = nil, convert_to_s = false) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/appsignal/hooks.rb', line 66 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
83 84 85 86 87 |
# File 'lib/appsignal/hooks.rb', line 83 def format_args(args) args.map do |arg| truncate(string_or_inspect(arg)) end end |
#string_or_inspect(string_or_other) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/appsignal/hooks.rb', line 54 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
62 63 64 |
# File 'lib/appsignal/hooks.rb', line 62 def truncate(text) text.size > 200 ? "#{text[0...197]}..." : text end |