# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true cs__scoped_require 'contrast/utils/duck_utils' module Contrast module Utils # This utility allows us to act on frozen objects, creating an unfrozen # duplicate in those cases where that is possible. class FreezeUtil class << self # Make every attempt to duplicate the frozen object so that it can # be tracked. # # @param original [Object] something frozen, usually a String # @return [Object] the original or an unfrozen copy def unfreeze_dup original return original unless original.cs__frozen? copy = original.dup if Contrast::Utils::DuckUtils.iterable_hash?(copy) copy.each_key do |key| value = original[key] copy[key] = value.dup end end copy end end end end end