lib/wcc/contentful/downloads_schema.rb in wcc-contentful-1.3.2 vs lib/wcc/contentful/downloads_schema.rb in wcc-contentful-1.4.0.rc1
- old
+ new
@@ -23,11 +23,12 @@
def update!
FileUtils.mkdir_p(File.dirname(@file))
File.write(@file, format_json({
'contentTypes' => content_types,
- 'editorInterfaces' => editor_interfaces
+ 'editorInterfaces' => editor_interfaces,
+ 'locales' => locales
}))
end
def needs_update?
return true unless File.exist?(@file)
@@ -43,12 +44,15 @@
return true unless content_types.count == existing_cts.count
return true unless deep_contains_all(content_types, existing_cts)
existing_eis = contents['editorInterfaces'].sort_by { |i| i.dig('sys', 'contentType', 'sys', 'id') }
return true unless editor_interfaces.count == existing_eis.count
+ return true unless deep_contains_all(editor_interfaces, existing_eis)
- !deep_contains_all(editor_interfaces, existing_eis)
+ existing_locales = contents['locales'].sort_by { |i| i.dig('sys', 'contentType', 'sys', 'id') }
+ return true unless locales.count == existing_locales.count
+ return true unless deep_contains_all(locales, existing_locales)
end
def content_types
@content_types ||=
@client.content_types(limit: 1000)
@@ -61,9 +65,17 @@
@editor_interfaces ||=
content_types
.map { |ct| @client.editor_interface(ct.dig('sys', 'id')).raw }
.map { |i| sort_controls(strip_sys(i)) }
.sort_by { |i| i.dig('sys', 'contentType', 'sys', 'id') }
+ end
+
+ def locales
+ @locales ||=
+ @client.locales(limit: 1000)
+ .items
+ .map { |l| strip_sys(l) }
+ .sort_by { |l| l.dig('sys', 'code') }
end
private
def strip_sys(obj)