lib/hedgelog/normalizer.rb in hedgelog-0.1.9 vs lib/hedgelog/normalizer.rb in hedgelog-0.1.11
- old
+ new
@@ -1,14 +1,12 @@
class Hedgelog
class Normalizer
- # rubocop:disable Security/MarshalLoad
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
- # rubocop:enable Security/MarshalLoad
def normalize_struct(struct)
normalize_hash(Hash[struct.each_pair.to_a])
end
@@ -20,17 +18,17 @@
def normalize_array(array)
array.to_json
end
- private
-
- def normalize_thing(thing)
+ 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