contentful_bootstrap 3.9.0 → 3.9.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4d0bf2dba800e936efa11794d15440a1da64db05
4
- data.tar.gz: 9af2801f2a777c99d2dd4f46bb6323964b7592a9
3
+ metadata.gz: e58541eab6426bb8208b9b0c33244d1bea9d65fa
4
+ data.tar.gz: d0e26fbf73b7e1c01e080eb1268dc90bab01cee0
5
5
  SHA512:
6
- metadata.gz: 9de02a76a5062f9c084f886168c9d41d800cb72d44bfdab9c8437e61ed9dbab30b1d0d4bdfb821e9bb95262ff86aaabe3f831f37a4f64a86e88bdebe07d6feb1
7
- data.tar.gz: 0b37f36ec8d8b5cd26112f071180bcbdaa1838ec239b485bb1f22dbdd2f32bda827e6d6fcd8a6cbf8d73046a722db6130d5744ec39a15f5edea703f3a555e33d
6
+ metadata.gz: 03150c56609259ab73f72026b0feaf962db95cb7b75066dc8166f03568b2022ff73111021bd23220ba3cd0291993d2b65826243d7ba56df906830aaa8fea2ec2
7
+ data.tar.gz: 22f9528bb02b02b60ffa529df0623c156c1816b8bb8f26e7370bdb93f83284cdeed8c5c9e684c9aae93ccf233792ee065e516c920be6c06e487e721d5009807f
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## v3.9.1
6
+ ### Fixed
7
+ * Fixed an issue in which assets save as `Contentful::Management::File` objects instead of as JSON when using `--mark-processed`.
8
+
5
9
  ## v3.9.0
6
10
  ### Fixed
7
11
  * Fixed `quiet` not being forwarded properly to `generate_json` and `update_space`
@@ -34,15 +34,18 @@ module Contentful
34
34
  def after_run
35
35
  return unless mark_processed?
36
36
 
37
- @json.fetch(CONTENT_TYPES_KEY, []).each do |content_type|
37
+ # Re-parse JSON to avoid side effects from `Templates::Base`
38
+ @json = parse_json
39
+
40
+ json.fetch(CONTENT_TYPES_KEY, []).each do |content_type|
38
41
  content_type[BOOTSTRAP_PROCCESSED_KEY] = true
39
42
  end
40
43
 
41
- @json.fetch(ASSETS_KEY, []).each do |asset|
44
+ json.fetch(ASSETS_KEY, []).each do |asset|
42
45
  asset[BOOTSTRAP_PROCCESSED_KEY] = true
43
46
  end
44
47
 
45
- @json.fetch(ENTRIES_KEY, {}).each do |_content_type_name, entry_list|
48
+ json.fetch(ENTRIES_KEY, {}).each do |_content_type_name, entry_list|
46
49
  entry_list.each do |entry|
47
50
  if entry.key?(SYS_KEY)
48
51
  entry[SYS_KEY][BOOTSTRAP_PROCCESSED_KEY] = true
@@ -55,8 +58,19 @@ module Contentful
55
58
  ::File.write(@file, JSON.pretty_generate(@json))
56
59
  end
57
60
 
61
+ def json
62
+ @json ||= parse_json
63
+ end
64
+
58
65
  private
59
66
 
67
+ def parse_json
68
+ ::JSON.parse(::File.read(@file))
69
+ rescue
70
+ output 'File is not JSON. Exiting!'
71
+ exit(1)
72
+ end
73
+
60
74
  def check_version
61
75
  json_version = json.fetch('version', 0)
62
76
  gem_major_version = Contentful::Bootstrap.major_version
@@ -65,13 +79,6 @@ module Contentful
65
79
  end
66
80
  end
67
81
 
68
- def json
69
- @json ||= ::JSON.parse(::File.read(@file))
70
- rescue
71
- output 'File is not JSON. Exiting!'
72
- exit(1)
73
- end
74
-
75
82
  def process_content_types
76
83
  processed_content_types = json.fetch(CONTENT_TYPES_KEY, [])
77
84
 
@@ -127,8 +134,8 @@ module Contentful
127
134
  processed_entry['id'] = entry[SYS_KEY]['id'] if entry.key?(SYS_KEY) && entry[SYS_KEY].key?('id')
128
135
 
129
136
  entry.fetch('fields', {}).each do |field, value|
130
- link_fields << field if is_link?(value)
131
- array_fields << field if is_array?(value)
137
+ link_fields << field if link?(value)
138
+ array_fields << field if array?(value)
132
139
 
133
140
  unless link_fields.include?(field) || array_fields.include?(field)
134
141
  processed_entry[field] = value
@@ -141,7 +148,7 @@ module Contentful
141
148
 
142
149
  array_fields.each do |af|
143
150
  processed_entry[af] = entry['fields'][af].map do |item|
144
- is_link?(item) ? create_link(item) : item
151
+ link?(item) ? create_link(item) : item
145
152
  end
146
153
  end
147
154
 
@@ -173,11 +180,11 @@ module Contentful
173
180
  @mark_processed
174
181
  end
175
182
 
176
- def is_link?(value)
183
+ def link?(value)
177
184
  value.is_a?(::Hash) && value.key?('id') && value.key?('linkType')
178
185
  end
179
186
 
180
- def is_array?(value)
187
+ def array?(value)
181
188
  value.is_a?(::Array)
182
189
  end
183
190
  end
@@ -1,6 +1,6 @@
1
1
  module Contentful
2
2
  module Bootstrap
3
- VERSION = '3.9.0'
3
+ VERSION = '3.9.1'
4
4
 
5
5
  def self.major_version
6
6
  VERSION.split('.').first.to_i
@@ -178,7 +178,50 @@ describe Contentful::Bootstrap::Templates::JsonTemplate do
178
178
  end
179
179
 
180
180
  expect(subject).to receive(:after_run).and_call_original
181
- expect(::File).to receive(:write)
181
+
182
+ expected = {
183
+ "version": 3,
184
+ "contentTypes": [
185
+ {
186
+ "id": "cat",
187
+ "name": "Cat",
188
+ "displayField": "name",
189
+ "fields": [
190
+ {
191
+ "id": "name",
192
+ "name": "Name",
193
+ "type": "Symbol"
194
+ }
195
+ ],
196
+ "bootstrapProcessed": true
197
+ }
198
+ ],
199
+ "assets": [
200
+ {
201
+ "id": "cat_asset",
202
+ "title": "Cat",
203
+ "file": {
204
+ "filename": "cat",
205
+ "url": "https://somecat.com/my_cat.jpeg"
206
+ },
207
+ "bootstrapProcessed": true
208
+ }
209
+ ],
210
+ "entries": {
211
+ "cat": [
212
+ {
213
+ "sys": {
214
+ "id": "nyancat",
215
+ "bootstrapProcessed": true
216
+ },
217
+ "fields": {
218
+ "name": "Nyan Cat"
219
+ }
220
+ }
221
+ ]
222
+ }
223
+ }
224
+ expect(::File).to receive(:write).with(path, JSON.pretty_generate(expected))
182
225
 
183
226
  subject.run
184
227
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contentful_bootstrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.9.0
4
+ version: 3.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Litvak Bruno
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-13 00:00:00.000000000 Z
11
+ date: 2017-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler