Sha256: 5abfb7420a96e67083390b0cb5fba8b492a9bdd34f432e4b263f6e1300057270
Contents?: true
Size: 844 Bytes
Versions: 4
Compression:
Stored size: 844 Bytes
Contents
class Hedgelog class Normalizer def normalize(data) # Need to Marshal.dump/Marshal.load to deep copy the input so that scrubbing doesn't change global state d = Marshal.load(Marshal.dump(data)) normalize_hash(d) end def normalize_struct(struct) normalize_hash(struct.each_pair.to_a.to_h) end def normalize_hash(hash) hash.transform_values do |val| normalize_thing(val) end end def normalize_array(array) array.to_json end private def normalize_thing(thing) return '' if thing.nil? thing = thing.as_json if thing.respond_to?(:as_json) return normalize_struct(thing) if thing.is_a?(Struct) return normalize_array(thing) if thing.is_a?(Array) return normalize_hash(thing) if thing.is_a?(Hash) thing end end end
Version data entries
4 entries across 4 versions & 1 rubygems