move all HashWithIndifferentAccess recursive enhancement over to the Util class
TODO: moving this two a class method on HashWithIndifferentAccess would really make the most sense, but there are two blockers: - historically the method has operated out of Util. While totally ok, simply dedeferring to HashWithIndifferentAccess feels a bit awkward - the contracts gem doesn’t support class method at this time. the assurance of frozen output is important considering the uses of the recursively_enhance method
This commit is contained in:
parent
a771b15700
commit
14e1cb1cd6
2 changed files with 6 additions and 20 deletions
|
@ -19,7 +19,7 @@ module Middleman
|
|||
super()
|
||||
|
||||
hash.each do |key, val|
|
||||
self[key] = recursively_enhance(val)
|
||||
self[key] = Util.recursively_enhance(val)
|
||||
end
|
||||
|
||||
freeze
|
||||
|
@ -82,22 +82,6 @@ module Middleman
|
|||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
Contract Any => Frozen[Any]
|
||||
def recursively_enhance(data)
|
||||
if data.is_a? HashWithIndifferentAccess
|
||||
data
|
||||
elsif data.is_a? Hash
|
||||
self.class.new(data)
|
||||
elsif data.is_a? Array
|
||||
data.map(&method(:recursively_enhance)).freeze
|
||||
elsif data.frozen? || data.nil? || [::TrueClass, ::FalseClass, ::Fixnum].include?(data.class)
|
||||
data
|
||||
else
|
||||
data.dup.freeze
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue