contentful 2.16.3 → 2.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -1
- data/README.md +2 -2
- data/lib/contentful/array.rb +2 -1
- data/lib/contentful/base_resource.rb +1 -1
- data/lib/contentful/coercions.rb +1 -4
- data/lib/contentful/entry.rb +4 -3
- data/lib/contentful/fields_resource.rb +3 -2
- data/lib/contentful/includes.rb +74 -0
- data/lib/contentful/resource_builder.rb +4 -3
- data/lib/contentful/support.rb +0 -35
- data/lib/contentful/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44bcfad09bdb03cc6460ebf0ac778f89e1b2820b9434f76bbbc297f63f84f7c7
|
4
|
+
data.tar.gz: a36e3d13ed3b67c501c34ceb7c777f60592188944905048839720d48490886d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 171a6d3f675e9596a9353c40d43ab5ee81fabf755407e13933fdf04a7934d1db058d33480b25a305609b52a27e00d46f6790a1186608495815b93cc29c0648d9
|
7
|
+
data.tar.gz: 763fc3a03017b6c10a5fdee30d6bd71eca0f0015aacbf4e3f250186985d347a20363d817265c4e6aa777b06b73df0817c865d4d9ddba8b3e0cace9b177eb62fb
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
##
|
3
|
+
## 2.17.0
|
4
|
+
|
5
|
+
### Updated
|
6
|
+
* Updated `http` gem version
|
7
|
+
|
8
|
+
### Changed
|
9
|
+
* CI/CD vendor from travis to circleci
|
10
|
+
* Refactored `includes` to be a model (`Contentful::Includes`) with a lookup table instead of a plain Ruby array, for improved performance when `include_level` is set. Two related methods from `Support` have been moved to this new class. Any code that uses the undocumented `includes_for_single` option to any method will need to be updated. [#235](https://github.com/contentful/contentful.rb/pull/235)
|
4
11
|
|
5
12
|
## 2.16.3
|
6
13
|
### Fixed
|
data/README.md
CHANGED
@@ -21,8 +21,8 @@
|
|
21
21
|
<img src="https://img.shields.io/badge/license-MIT-brightgreen.svg" alt="MIT License" />
|
22
22
|
</a>
|
23
23
|
|
24
|
-
<a href="https://
|
25
|
-
<img src="https://
|
24
|
+
<a href="https://app.circleci.com/pipelines/github/contentful/contentful.rb?branch=master">
|
25
|
+
<img src="https://circleci.com/gh/contentful/contentful.rb/tree/master.svg?style=svg" alt="CircleCI">
|
26
26
|
</a>
|
27
27
|
</p>
|
28
28
|
|
data/lib/contentful/array.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require_relative 'base_resource'
|
2
2
|
require_relative 'array_like'
|
3
|
+
require_relative 'includes'
|
3
4
|
|
4
5
|
module Contentful
|
5
6
|
# Resource Class for Arrays (e.g. search results)
|
@@ -47,7 +48,7 @@ module Contentful
|
|
47
48
|
require_relative 'resource_builder'
|
48
49
|
ResourceBuilder.new(
|
49
50
|
item.raw,
|
50
|
-
raw_object[:configuration].merge(includes_for_single:
|
51
|
+
raw_object[:configuration].merge(includes_for_single: Includes.from_response(raw, false)),
|
51
52
|
item.respond_to?(:localized) ? item.localized : false,
|
52
53
|
0,
|
53
54
|
raw_object[:configuration][:errors] || []
|
@@ -8,7 +8,7 @@ module Contentful
|
|
8
8
|
attr_reader :raw, :default_locale, :sys, :_metadata
|
9
9
|
|
10
10
|
# rubocop:disable Metrics/ParameterLists
|
11
|
-
def initialize(item, configuration = {}, _localized = false, _includes =
|
11
|
+
def initialize(item, configuration = {}, _localized = false, _includes = Includes.new, entries = {}, depth = 0, _errors = [])
|
12
12
|
entries["#{item['sys']['type']}:#{item['sys']['id']}"] = self if entries && item.key?('sys')
|
13
13
|
@raw = item
|
14
14
|
@default_locale = configuration[:default_locale]
|
data/lib/contentful/coercions.rb
CHANGED
@@ -155,10 +155,7 @@ module Contentful
|
|
155
155
|
|
156
156
|
return nil if Support.unresolvable?(node['data']['target'], configuration[:errors])
|
157
157
|
|
158
|
-
resource =
|
159
|
-
node['data']['target'],
|
160
|
-
configuration[:includes_for_single]
|
161
|
-
)
|
158
|
+
resource = configuration[:includes_for_single].find_link(node['data']['target'])
|
162
159
|
|
163
160
|
# Resource is valid but unreachable
|
164
161
|
return Link.new(node['data']['target'], configuration) if resource.nil?
|
data/lib/contentful/entry.rb
CHANGED
@@ -2,6 +2,7 @@ require_relative 'error'
|
|
2
2
|
require_relative 'fields_resource'
|
3
3
|
require_relative 'content_type_cache'
|
4
4
|
require_relative 'resource_references'
|
5
|
+
require_relative 'includes'
|
5
6
|
|
6
7
|
module Contentful
|
7
8
|
# Resource class for Entry.
|
@@ -30,7 +31,7 @@ module Contentful
|
|
30
31
|
content_type_field = content_type.field_for(field_id)
|
31
32
|
coercion_configuration = @configuration.merge(
|
32
33
|
includes_for_single:
|
33
|
-
@configuration.fetch(:includes_for_single,
|
34
|
+
@configuration.fetch(:includes_for_single, Includes.new) + includes,
|
34
35
|
_entries_cache: entries,
|
35
36
|
localized: localized,
|
36
37
|
depth: @depth,
|
@@ -58,7 +59,7 @@ module Contentful
|
|
58
59
|
# Any included object after the maximum include resolution depth will be just a Link
|
59
60
|
def build_nested_resource(value, includes, entries, errors)
|
60
61
|
if @depth < @configuration.fetch(:max_include_resolution_depth, 20)
|
61
|
-
resource =
|
62
|
+
resource = includes.find_link(value)
|
62
63
|
return resolve_include(resource, includes, entries, errors) unless resource.nil?
|
63
64
|
end
|
64
65
|
|
@@ -72,7 +73,7 @@ module Contentful
|
|
72
73
|
resource,
|
73
74
|
@configuration.merge(
|
74
75
|
includes_for_single:
|
75
|
-
@configuration.fetch(:includes_for_single,
|
76
|
+
@configuration.fetch(:includes_for_single, Includes.new) + includes,
|
76
77
|
_entries_cache: entries
|
77
78
|
),
|
78
79
|
localized,
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require_relative 'support'
|
4
4
|
require_relative 'base_resource'
|
5
|
+
require_relative 'includes'
|
5
6
|
|
6
7
|
module Contentful
|
7
8
|
# Base definition of a Contentful Resource containing Field properties
|
@@ -9,7 +10,7 @@ module Contentful
|
|
9
10
|
attr_reader :localized
|
10
11
|
|
11
12
|
# rubocop:disable Metrics/ParameterLists
|
12
|
-
def initialize(item, _configuration, localized = false, includes =
|
13
|
+
def initialize(item, _configuration, localized = false, includes = Includes.new, entries = {}, depth = 0, errors = [])
|
13
14
|
super
|
14
15
|
|
15
16
|
@configuration[:errors] = errors
|
@@ -56,7 +57,7 @@ module Contentful
|
|
56
57
|
super(raw_object)
|
57
58
|
@localized = raw_object[:localized]
|
58
59
|
@fields = hydrate_fields(
|
59
|
-
raw_object[:configuration].fetch(:includes_for_single,
|
60
|
+
raw_object[:configuration].fetch(:includes_for_single, Includes.new),
|
60
61
|
{},
|
61
62
|
raw_object[:configuration].fetch(:errors, [])
|
62
63
|
)
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require_relative 'array_like'
|
2
|
+
|
3
|
+
module Contentful
|
4
|
+
# The includes hashes returned when include_level is specified
|
5
|
+
class Includes
|
6
|
+
include ArrayLike
|
7
|
+
|
8
|
+
attr_accessor :items, :lookup
|
9
|
+
|
10
|
+
def initialize(items = [], lookup = nil)
|
11
|
+
self.items = items
|
12
|
+
self.lookup = lookup || build_lookup
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.from_response(json, raw = true)
|
16
|
+
includes = if raw
|
17
|
+
json['items'].dup
|
18
|
+
else
|
19
|
+
json['items'].map(&:raw)
|
20
|
+
end
|
21
|
+
|
22
|
+
%w[Entry Asset].each do |type|
|
23
|
+
includes.concat(json['includes'].fetch(type, [])) if json.fetch('includes', {}).key?(type)
|
24
|
+
end
|
25
|
+
|
26
|
+
new includes || []
|
27
|
+
end
|
28
|
+
|
29
|
+
def find_link(link)
|
30
|
+
key = "#{link['sys']['linkType']}:#{link['sys']['id']}"
|
31
|
+
lookup[key]
|
32
|
+
end
|
33
|
+
|
34
|
+
# Override some of the features of Array to take into account the lookup
|
35
|
+
# field in a performant way.
|
36
|
+
|
37
|
+
# If the lookups are the same then these two objects are effectively the same
|
38
|
+
def ==(other)
|
39
|
+
object_id == other.object_id || lookup == other.lookup
|
40
|
+
end
|
41
|
+
|
42
|
+
def +(other)
|
43
|
+
# If we're being asked to add to itself, just return without duplicating
|
44
|
+
return self if self == other
|
45
|
+
|
46
|
+
dup.tap do |copy|
|
47
|
+
copy.items += other.items
|
48
|
+
copy.lookup.merge!(other.lookup)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def dup
|
53
|
+
self.class.new(items.dup, lookup.dup)
|
54
|
+
end
|
55
|
+
|
56
|
+
def marshal_dump
|
57
|
+
items
|
58
|
+
end
|
59
|
+
|
60
|
+
def marshal_load(array)
|
61
|
+
self.items = array
|
62
|
+
self.lookup = build_lookup
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def build_lookup
|
68
|
+
items.each_with_object({}) do |i, h|
|
69
|
+
key = "#{i['sys']['type']}:#{i['sys']['id']}"
|
70
|
+
h[key] = i
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -8,6 +8,7 @@ require_relative 'link'
|
|
8
8
|
require_relative 'deleted_entry'
|
9
9
|
require_relative 'deleted_asset'
|
10
10
|
require_relative 'locale'
|
11
|
+
require_relative 'includes'
|
11
12
|
|
12
13
|
module Contentful
|
13
14
|
# Transforms a Contentful::Response into a Contentful::Resource or a Contentful::Error
|
@@ -39,7 +40,7 @@ module Contentful
|
|
39
40
|
@default_locale = configuration.fetch(:default_locale, ::Contentful::Client::DEFAULT_CONFIGURATION[:default_locale])
|
40
41
|
@resource_mapping = default_resource_mapping.merge(configuration.fetch(:resource_mapping, {}))
|
41
42
|
@entry_mapping = default_entry_mapping.merge(configuration.fetch(:entry_mapping, {}))
|
42
|
-
@includes_for_single = configuration.fetch(:includes_for_single,
|
43
|
+
@includes_for_single = configuration.fetch(:includes_for_single, Includes.new)
|
43
44
|
@localized = localized
|
44
45
|
@depth = depth
|
45
46
|
@endpoint = configuration.fetch(:endpoint, nil)
|
@@ -79,7 +80,7 @@ module Contentful
|
|
79
80
|
build_item(json, includes, @errors)
|
80
81
|
end
|
81
82
|
|
82
|
-
def build_item(item, includes =
|
83
|
+
def build_item(item, includes = Includes.new, errors = [])
|
83
84
|
item_type = BUILDABLES.detect { |b| b == item['sys']['type'] }
|
84
85
|
fail UnparsableResource, 'Item type is not known, could not parse' if item_type.nil?
|
85
86
|
item_class = resource_class(item)
|
@@ -98,7 +99,7 @@ module Contentful
|
|
98
99
|
end
|
99
100
|
|
100
101
|
def fetch_includes
|
101
|
-
|
102
|
+
Includes.from_response(json)
|
102
103
|
end
|
103
104
|
|
104
105
|
def fetch_errors
|
data/lib/contentful/support.rb
CHANGED
@@ -47,41 +47,6 @@ module Contentful
|
|
47
47
|
|
48
48
|
false
|
49
49
|
end
|
50
|
-
|
51
|
-
# Returns the resource that matches the link
|
52
|
-
#
|
53
|
-
# @param [Hash] link
|
54
|
-
# @param [::Array] includes
|
55
|
-
#
|
56
|
-
# @return [Hash]
|
57
|
-
def resource_for_link(link, includes)
|
58
|
-
includes.detect do |i|
|
59
|
-
i['sys']['id'] == link['sys']['id'] &&
|
60
|
-
i['sys']['type'] == link['sys']['linkType']
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
# Returns combined include array from an API Response
|
65
|
-
#
|
66
|
-
# @param [Hash] json JSON Response
|
67
|
-
# @param [Bool] raw Response pre-proccessed?
|
68
|
-
#
|
69
|
-
# @return [Array]
|
70
|
-
def includes_from_response(json, raw = true)
|
71
|
-
includes = if raw
|
72
|
-
json['items'].dup
|
73
|
-
else
|
74
|
-
json['items'].map(&:raw)
|
75
|
-
end
|
76
|
-
|
77
|
-
%w[Entry Asset].each do |type|
|
78
|
-
if json.fetch('includes', {}).key?(type)
|
79
|
-
includes.concat(json['includes'].fetch(type, []))
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
includes
|
84
|
-
end
|
85
50
|
end
|
86
51
|
end
|
87
52
|
end
|
data/lib/contentful/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contentful
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.17.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Contentful GmbH (Jan Lelis)
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2023-04-11 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: http
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0.8'
|
22
22
|
- - "<"
|
23
23
|
- !ruby/object:Gem::Version
|
24
|
-
version: '
|
24
|
+
version: '6.0'
|
25
25
|
type: :runtime
|
26
26
|
prerelease: false
|
27
27
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -31,7 +31,7 @@ dependencies:
|
|
31
31
|
version: '0.8'
|
32
32
|
- - "<"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '
|
34
|
+
version: '6.0'
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: multi_json
|
37
37
|
requirement: !ruby/object:Gem::Requirement
|
@@ -267,6 +267,7 @@ files:
|
|
267
267
|
- lib/contentful/field.rb
|
268
268
|
- lib/contentful/fields_resource.rb
|
269
269
|
- lib/contentful/file.rb
|
270
|
+
- lib/contentful/includes.rb
|
270
271
|
- lib/contentful/link.rb
|
271
272
|
- lib/contentful/locale.rb
|
272
273
|
- lib/contentful/location.rb
|
@@ -298,7 +299,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
298
299
|
- !ruby/object:Gem::Version
|
299
300
|
version: '0'
|
300
301
|
requirements: []
|
301
|
-
rubygems_version: 3.1.
|
302
|
+
rubygems_version: 3.1.6
|
302
303
|
signing_key:
|
303
304
|
specification_version: 4
|
304
305
|
summary: contentful
|