lib/contentful/resource_builder.rb in contentful-2.13.1 vs lib/contentful/resource_builder.rb in contentful-2.13.2
- old
+ new
@@ -23,14 +23,15 @@
'Array' => Array,
'Link' => Link,
'DeletedEntry' => DeletedEntry,
'DeletedAsset' => DeletedAsset,
'Locale' => Locale
- }
+ }.freeze
# Default Entry Mapping
# @see _ README for more information on Entry Mapping
- DEFAULT_ENTRY_MAPPING = {}
+ DEFAULT_ENTRY_MAPPING = {}.freeze
+ BUILDABLES = %w[Entry Asset ContentType Space DeletedEntry DeletedAsset Locale].freeze
attr_reader :json, :default_locale, :endpoint, :depth, :localized, :resource_mapping, :entry_mapping, :resource
def initialize(json, configuration = {}, localized = false, depth = 0, errors = [])
@json = json
@@ -65,22 +66,21 @@
result = json['items'].map do |item|
next if Support.unresolvable?(item, errors)
build_item(item, includes, errors)
end
array_class = fetch_array_class
- array_class.new(json.dup.merge('items' => result), @configuration, endpoint)
+ array_class.new(json.merge('items' => result), @configuration, endpoint)
end
def build_single
return if Support.unresolvable?(json, @errors)
includes = @includes_for_single
build_item(json, includes, @errors)
end
def build_item(item, includes = [], errors = [])
- buildables = %w[Entry Asset ContentType Space DeletedEntry DeletedAsset Locale]
- item_type = buildables.detect { |b| b.to_s == item['sys']['type'] }
+ item_type = BUILDABLES.detect { |b| b == item['sys']['type'] }
fail UnparsableResource, 'Item type is not known, could not parse' if item_type.nil?
item_class = resource_class(item)
reuse_entries = @configuration.fetch(:reuse_entries, false)
resource_cache = @resource_cache ? @resource_cache : {}
@@ -153,14 +153,14 @@
json.fetch('nextSyncUrl', nil) || json.fetch('nextPageUrl', nil)
end
# The default mapping for #detect_resource_class
def default_resource_mapping
- DEFAULT_RESOURCE_MAPPING.dup
+ DEFAULT_RESOURCE_MAPPING
end
# The default entry mapping
def default_entry_mapping
- DEFAULT_ENTRY_MAPPING.dup
+ DEFAULT_ENTRY_MAPPING
end
end
end