lib/contentful_middleman/mappers/base.rb in contentful_middleman-4.0.0 vs lib/contentful_middleman/mappers/base.rb in contentful_middleman-4.0.1

- old
+ new

@@ -7,10 +7,13 @@ def initialize(entries, options) @entries = entries @options = options @children = {} + @created_at_key = using_camel_case? ? :createdAt : :created_at + @updated_at_key = using_camel_case? ? :updatedAt : :updated_at + @content_type_key = using_camel_case? ? :contentType : :content_type end def map(context, entry) @children = { :queue => [{ :context => context, :entry => entry }], @@ -23,10 +26,14 @@ end end private + def using_camel_case? + @options.client_options.fetch(:use_camel_case, false) + end + def has_multiple_locales? @options.cda_query.fetch(:locale, nil) == '*' end def map_field(context, field_name, field_value) @@ -59,12 +66,12 @@ end end def map_asset_metadata(asset) context = Context.new - context.updated_at = asset.sys[:updated_at].iso8601 unless asset.sys[:updated_at].nil? - context.created_at = asset.sys[:created_at].iso8601 unless asset.sys[:created_at].nil? + context.updated_at = asset.sys[@updated_at_key].iso8601 unless asset.sys[@updated_at_key].nil? + context.created_at = asset.sys[@created_at_key].iso8601 unless asset.sys[@created_at_key].nil? context.id = asset.sys[:id] context end @@ -85,12 +92,12 @@ context end def map_entry_metadata(entry) context = Context.new - context.content_type_id = entry.sys[:content_type].id unless entry.sys[:content_type].nil? - context.updated_at = entry.sys[:updated_at].iso8601 unless entry.sys[:updated_at].nil? - context.created_at = entry.sys[:created_at].iso8601 unless entry.sys[:created_at].nil? + context.content_type_id = entry.sys[@content_type_key].id unless entry.sys[@content_type_key].nil? + context.updated_at = entry.sys[@updated_at_key].iso8601 unless entry.sys[@updated_at_key].nil? + context.created_at = entry.sys[@created_at_key].iso8601 unless entry.sys[@created_at_key].nil? context.id = entry.sys[:id] context end