Module: Bugsnag::Helpers
- Defined in:
- lib/bugsnag/helpers.rb
Constant Summary collapse
- MAX_STRING_LENGTH =
4096
Class Method Summary collapse
- .cleanup_obj(obj, filters = nil) ⇒ Object
-
.dump_json(object, options = {}) ⇒ Object
Helper functions to work around MultiJson changes in 1.3+.
- .flatten_meta_data(overrides) ⇒ Object
- .load_json(json, options = {}) ⇒ Object
- .reduce_hash_size(hash) ⇒ Object
Class Method Details
.cleanup_obj(obj, filters = nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/bugsnag/helpers.rb', line 13 def self.cleanup_obj(obj, filters = nil) return nil unless obj if obj.is_a?(Hash) clean_hash = {} obj.each do |k,v| if filters && filters.any? {|f| k.to_s.include?(f.to_s)} clean_hash[k] = "[FILTERED]" else clean_obj = cleanup_obj(v, filters) clean_hash[k] = clean_obj unless clean_obj.nil? end end clean_hash elsif obj.is_a?(Array) || obj.is_a?(Set) obj.map { |el| cleanup_obj(el, filters) }.compact elsif obj.is_a?(Integer) || obj.is_a?(Float) || obj.is_a?(String) obj else obj.to_s unless obj.to_s =~ /#<.*>/ end end |
.dump_json(object, options = {}) ⇒ Object
Helper functions to work around MultiJson changes in 1.3+
63 64 65 66 67 68 69 |
# File 'lib/bugsnag/helpers.rb', line 63 def self.dump_json(object, ={}) if MultiJson.respond_to?(:adapter) MultiJson.dump(object, ) else MultiJson.encode(object, ) end end |
.flatten_meta_data(overrides) ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/bugsnag/helpers.rb', line 51 def self.(overrides) return nil unless overrides = overrides.delete(:meta_data) if .is_a?(Hash) overrides.merge() else overrides end end |
.load_json(json, options = {}) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/bugsnag/helpers.rb', line 71 def self.load_json(json, ={}) if MultiJson.respond_to?(:adapter) MultiJson.load(json, ) else MultiJson.decode(json, ) end end |
.reduce_hash_size(hash) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/bugsnag/helpers.rb', line 36 def self.reduce_hash_size(hash) return {} unless hash.is_a?(Hash) hash.inject({}) do |h, (k,v)| if v.is_a?(Hash) h[k] = reduce_hash_size(v) elsif v.is_a?(Array) || v.is_a?(Set) h[k] = v.map {|el| reduce_hash_size(el) } else h[k] = v.to_s.slice(0, MAX_STRING_LENGTH) + "[TRUNCATED]" end h end end |