Use Hashie Mash for recursive indifferent

This commit is contained in:
Thomas Reynolds 2015-08-18 16:22:32 -07:00
parent 0861fad2e1
commit 3485f49f74

View file

@ -76,10 +76,10 @@ module Middleman
end end
end end
class EnhancedHash < ::Hash class EnhancedHash < ::Hashie::Mash
include ::Hashie::Extensions::MergeInitializer # include ::Hashie::Extensions::MergeInitializer
include ::Hashie::Extensions::MethodReader # include ::Hashie::Extensions::MethodReader
include ::Hashie::Extensions::IndifferentAccess # include ::Hashie::Extensions::IndifferentAccess
end end
# Recursively convert a normal Hash into a EnhancedHash # Recursively convert a normal Hash into a EnhancedHash
@ -90,9 +90,9 @@ module Middleman
Contract Maybe[Hash] => Maybe[Or[Array, EnhancedHash]] Contract Maybe[Hash] => Maybe[Or[Array, EnhancedHash]]
def recursively_enhance(obj) def recursively_enhance(obj)
if obj.is_a? ::Array if obj.is_a? ::Array
obj.map { |e| recursively_enhance(e) }.freeze obj.map { |e| recursively_enhance(e) }
elsif obj.is_a? ::Hash elsif obj.is_a? ::Hash
EnhancedHash.new(obj).freeze ::Hashie::Mash.new(obj)
else else
obj obj
end end