contentful-database-importer 0.2.0 → 0.3.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/.rubocop.yml +13 -0
- data/CHANGELOG.md +11 -0
- data/README.md +13 -1
- data/contentful-database-importer.gemspec +1 -2
- data/lib/contentful/database_importer/id_generator/base.rb +2 -5
- data/lib/contentful/database_importer/json_generator.rb +1 -3
- data/lib/contentful/database_importer/resource.rb +5 -3
- data/lib/contentful/database_importer/resource_bootstrap_class_methods.rb +2 -7
- data/lib/contentful/database_importer/resource_coercions.rb +4 -2
- data/lib/contentful/database_importer/resource_field_class_methods.rb +1 -4
- data/lib/contentful/database_importer/resource_relationships.rb +6 -4
- data/lib/contentful/database_importer/version.rb +1 -1
- metadata +5 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0302793d39ecf33e81c86cafe39e6125a5851c75
|
4
|
+
data.tar.gz: 3a24e01de0daf7d481a2bd13f0c2052bd3b0b880
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e042169712b3bd6c3069e2b5f16ab88b58080610f2029bdc52e7b663c37e363c2e72e65be9864448875fcab0fe1d2eaae85f5c12aacdc06dbb9b27459e685550
|
7
|
+
data.tar.gz: 9e32f719aaf1337a003a471b2cda2b215d74ad28d2bf297f880124b5242c9deb3069c675bf09841d2d91d75a7da94eba200f045d562e6b280033a8ce90d00cdc
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2017-01-30 13:40:58 -0300 using RuboCop version 0.47.1.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 6
|
10
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
11
|
+
# URISchemes: http, https
|
12
|
+
Metrics/LineLength:
|
13
|
+
Max: 100
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -18,6 +18,10 @@ Contentful offers tools for managing editorial teams and enabling cooperation be
|
|
18
18
|
you to generate a JSON file that's a valid [`contentful_bootstrap`](https://github.com/contentful/contentful-bootstrap.rb) JSON Template,
|
19
19
|
or directly import to Contentful, creating a new space and using your data to populate the content.
|
20
20
|
|
21
|
+
## Requirements
|
22
|
+
|
23
|
+
* Ruby
|
24
|
+
* A Relational Database
|
21
25
|
|
22
26
|
## Installation
|
23
27
|
|
@@ -41,6 +45,14 @@ source 'https://rubygems.org'
|
|
41
45
|
gem 'contentful-database-importer'
|
42
46
|
```
|
43
47
|
|
48
|
+
* Add to your _`Gemfile`_ the handler specific to your database (e.g.):
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
gem 'pg' # if using Postgres
|
52
|
+
gem 'sqlite3' # if using SQLite
|
53
|
+
gem 'mysql' # if using MySQL
|
54
|
+
```
|
55
|
+
|
44
56
|
* Create your importer file, for example _`import.rb`_:
|
45
57
|
|
46
58
|
```ruby
|
@@ -143,7 +155,7 @@ The options are:
|
|
143
155
|
- `:boolean`: Boolean.
|
144
156
|
- `:location`: Geographical Location (can be coerced from a String, Hash or Array.)
|
145
157
|
- `:date`: An ISO8601 Date (can be coerced from a Date/DateTime object or String).
|
146
|
-
- `:object`: A JSON Object.
|
158
|
+
- `:object`: A JSON Object.
|
147
159
|
- `:asset`: A File description. A String containing the file URL needs to be provided.
|
148
160
|
- `:array`: An Array of elements.
|
149
161
|
|
@@ -19,8 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_dependency 'contentful_bootstrap', '~> 3.
|
23
|
-
spec.add_dependency 'contentful-management', '~> 0.9'
|
22
|
+
spec.add_dependency 'contentful_bootstrap', '~> 3.5'
|
24
23
|
spec.add_dependency 'sequel', '~> 4.39'
|
25
24
|
spec.add_dependency 'base62-rb'
|
26
25
|
spec.add_dependency 'mimemagic'
|
@@ -23,11 +23,8 @@ module Contentful
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def find_on_entry(entry_data, match)
|
26
|
-
if entry_data.excluded_fields.key?(match)
|
27
|
-
|
28
|
-
elsif entry_data.bootstrap_fields.key?(match)
|
29
|
-
return entry_data.bootstrap_fields[match]
|
30
|
-
end
|
26
|
+
return entry_data.excluded_fields[match] if entry_data.excluded_fields.key?(match)
|
27
|
+
return entry_data.bootstrap_fields[match] if entry_data.bootstrap_fields.key?(match)
|
31
28
|
|
32
29
|
raise "Template could not be resolved, #{match} not found."
|
33
30
|
end
|
@@ -67,9 +67,7 @@ module Contentful
|
|
67
67
|
|
68
68
|
merge_entries(entry_definition, content_type_definition, result)
|
69
69
|
|
70
|
-
result[:assets].concat(
|
71
|
-
entry.associated_assets
|
72
|
-
) unless entry.associated_assets.empty?
|
70
|
+
result[:assets].concat(entry.associated_assets) unless entry.associated_assets.empty?
|
73
71
|
|
74
72
|
result[:entries][content_type_definition[:id]] << entry_definition
|
75
73
|
end
|
@@ -79,9 +79,11 @@ module Contentful
|
|
79
79
|
end
|
80
80
|
|
81
81
|
def id
|
82
|
-
self.class.id_generator
|
83
|
-
self.class.
|
84
|
-
|
82
|
+
if self.class.id_generator.nil?
|
83
|
+
self.class.id_generator = IdGenerator::Base.new(
|
84
|
+
self.class.default_generator_options
|
85
|
+
)
|
86
|
+
end
|
85
87
|
|
86
88
|
self.class.id_generator.run(self, index)
|
87
89
|
end
|
@@ -32,10 +32,7 @@ module Contentful
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def items_type(field_data)
|
35
|
-
return {
|
36
|
-
type: 'Link',
|
37
|
-
linkType: array_link_type(field_data)
|
38
|
-
} if array_link?(field_data)
|
35
|
+
return { type: 'Link', linkType: array_link_type(field_data) } if array_link?(field_data)
|
39
36
|
|
40
37
|
type = definition_type(field_data[:item_type])
|
41
38
|
|
@@ -88,9 +85,7 @@ module Contentful
|
|
88
85
|
definition = basic_field_definition(field_data)
|
89
86
|
|
90
87
|
definition[:type] = 'Array' if array?(field_data)
|
91
|
-
definition[:linkType] = link_type(
|
92
|
-
field_data[:type]
|
93
|
-
) if link_type?(field_data)
|
88
|
+
definition[:linkType] = link_type(field_data[:type]) if link_type?(field_data)
|
94
89
|
definition[:items] = items_type(field_data) if array?(field_data)
|
95
90
|
|
96
91
|
definition
|
@@ -79,8 +79,10 @@ module Contentful
|
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
-
def coerce_object(
|
83
|
-
|
82
|
+
def coerce_object(value)
|
83
|
+
return value if value.is_a?(::Hash)
|
84
|
+
|
85
|
+
raise "Can't coerce #{value} to JSON Object"
|
84
86
|
end
|
85
87
|
|
86
88
|
def create_associated_asset(name, value)
|
@@ -29,10 +29,7 @@ module Contentful
|
|
29
29
|
def prepare_field(database_name, options)
|
30
30
|
field = prepare_standard_field_options(database_name, options)
|
31
31
|
field[:item_type] = options.fetch(:item_type) if field[:type] == :array
|
32
|
-
fetch_relationship_options(
|
33
|
-
field,
|
34
|
-
options
|
35
|
-
) if options.fetch(:relationship, false)
|
32
|
+
fetch_relationship_options(field, options) if options.fetch(:relationship, false)
|
36
33
|
|
37
34
|
field
|
38
35
|
end
|
@@ -4,10 +4,12 @@ module Contentful
|
|
4
4
|
module ResourceRelationships
|
5
5
|
def fetch_relations(relationship_field_definition)
|
6
6
|
relations = [:many, :one, :through]
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
if relations.include?(relationship_field_definition[:relationship])
|
8
|
+
return send(
|
9
|
+
"fetch_#{relationship_field_definition[:relationship]}".to_sym,
|
10
|
+
relationship_field_definition
|
11
|
+
)
|
12
|
+
end
|
11
13
|
|
12
14
|
raise 'Invalid Relationship type'
|
13
15
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contentful-database-importer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Contentful GmbH (David Litvak Bruno)
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: contentful_bootstrap
|
@@ -16,28 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '3.
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '3.0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: contentful-management
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0.9'
|
19
|
+
version: '3.5'
|
34
20
|
type: :runtime
|
35
21
|
prerelease: false
|
36
22
|
version_requirements: !ruby/object:Gem::Requirement
|
37
23
|
requirements:
|
38
24
|
- - "~>"
|
39
25
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
26
|
+
version: '3.5'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: sequel
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -215,6 +201,7 @@ extra_rdoc_files: []
|
|
215
201
|
files:
|
216
202
|
- ".gitignore"
|
217
203
|
- ".rspec"
|
204
|
+
- ".rubocop.yml"
|
218
205
|
- ".travis.yml"
|
219
206
|
- CHANGELOG.md
|
220
207
|
- CODE_OF_CONDUCT.md
|