lib/contentful_middleman/mappers/base.rb in contentful_middleman-4.0.1 vs lib/contentful_middleman/mappers/base.rb in contentful_middleman-4.1.0
- old
+ new
@@ -59,10 +59,12 @@
map_link(value)
when Contentful::Entry
map_entry(value)
when Array
map_array(value, locale)
+ when Hash
+ map_hash(value, locale)
else
value
end
end
@@ -137,9 +139,20 @@
context
end
def map_array(array, locale = nil)
array.map {|element| map_value(element, locale)}
+ end
+
+ def map_hash(hash, locale = nil)
+ return hash.transform_values {|element| map_value(element, locale)} if hash.respond_to?(:transform_values)
+
+ # Support for Ruby versions previous to 2.4
+ result = {}
+ hash.each do |k, v|
+ result[k] = map_value(v, locale)
+ end
+ result
end
end
end
end