abstract_importer 1.0.0 → 1.1.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/.travis.yml +8 -0
- data/README.md +4 -0
- data/lib/abstract_importer/base.rb +5 -4
- data/lib/abstract_importer/collection_importer.rb +8 -30
- data/lib/abstract_importer/id_map.rb +4 -0
- data/lib/abstract_importer/reporter.rb +16 -13
- data/lib/abstract_importer/summary.rb +9 -0
- data/lib/abstract_importer/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 390699648f23aa027bf392f0f9095bf4b6801e3b
|
4
|
+
data.tar.gz: 5f1d0ccb8c4db21649913fa3914b7f6a4f0ba22c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1081c7623c65fcbd0748385d6e30f139dcf0d33703ace0c172e9b3e2d9a07aac3cabff0de5f600dc40dc0de7d28af5de2d0865960252888bb5b101711c8ed252
|
7
|
+
data.tar.gz: b59ab4abc7f8c9634e00c24840a01dfe0974f5b7f57e8f34b57129ad10e8d7f0c226972c3323b67107b3aeec6741b2f9e7aaf072ccc8515dbae308c59ca8072b
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# AbstractImporter
|
2
2
|
|
3
|
+
[](https://travis-ci.org/concordia-publishing-house/abstract_importer)
|
4
|
+
|
5
|
+
[](https://codeclimate.com/github/concordia-publishing-house/abstract_importer)
|
6
|
+
|
3
7
|
AbstractImporter provides services for importing complex data from an arbitrary data source. It:
|
4
8
|
|
5
9
|
* Preserves relationships between tables that are imported as a set
|
@@ -4,6 +4,7 @@ require 'abstract_importer/reporter'
|
|
4
4
|
require 'abstract_importer/collection'
|
5
5
|
require 'abstract_importer/collection_importer'
|
6
6
|
require 'abstract_importer/id_map'
|
7
|
+
require 'abstract_importer/summary'
|
7
8
|
|
8
9
|
|
9
10
|
module AbstractImporter
|
@@ -28,12 +29,12 @@ module AbstractImporter
|
|
28
29
|
@dry_run = options.fetch(:dry_run, false)
|
29
30
|
|
30
31
|
@id_map = IdMap.new
|
31
|
-
@
|
32
|
+
@results = {}
|
32
33
|
@import_plan = self.class.import_plan.to_h
|
33
34
|
@collections = []
|
34
35
|
end
|
35
36
|
|
36
|
-
attr_reader :source, :parent, :reporter, :id_map, :
|
37
|
+
attr_reader :source, :parent, :reporter, :id_map, :results
|
37
38
|
|
38
39
|
def dry_run?
|
39
40
|
@dry_run
|
@@ -57,7 +58,7 @@ module AbstractImporter
|
|
57
58
|
|
58
59
|
teardown
|
59
60
|
reporter.finish_all(self, ms)
|
60
|
-
|
61
|
+
results
|
61
62
|
end
|
62
63
|
|
63
64
|
def setup
|
@@ -68,7 +69,7 @@ module AbstractImporter
|
|
68
69
|
end
|
69
70
|
|
70
71
|
def import_collection(collection)
|
71
|
-
|
72
|
+
results[collection.name] = CollectionImporter.new(self, collection).perform!
|
72
73
|
end
|
73
74
|
|
74
75
|
def teardown
|
@@ -30,7 +30,7 @@ module AbstractImporter
|
|
30
30
|
reporter.start_collection(self)
|
31
31
|
prepare!
|
32
32
|
|
33
|
-
summary
|
33
|
+
summary.ms = Benchmark.ms do
|
34
34
|
each_new_record &method(:process_record)
|
35
35
|
end
|
36
36
|
|
@@ -42,32 +42,10 @@ module AbstractImporter
|
|
42
42
|
|
43
43
|
|
44
44
|
def prepare!
|
45
|
-
|
46
|
-
@summary = [ 0, 0, 0, 0, 0, 0]
|
47
|
-
@already_imported = load_already_imported_records!
|
45
|
+
@summary = Summary.new
|
48
46
|
@mappings = prepare_mappings!
|
49
47
|
end
|
50
48
|
|
51
|
-
def load_already_imported_records!
|
52
|
-
# We keep a _separate_ list of legacy IDs that
|
53
|
-
# have already been imported. It would optimal to
|
54
|
-
# check @id_map to see if a record has been imported;
|
55
|
-
# but because of a bug with tags, that won't work:
|
56
|
-
#
|
57
|
-
# Tags import from three table: Activity, Skill,
|
58
|
-
# and Training. Those tables yield tags whose
|
59
|
-
# legacy_ids collide. As a result several tags
|
60
|
-
# can share the same ID; and tags that would collide
|
61
|
-
# are [erroneously] not imported.
|
62
|
-
#
|
63
|
-
# Fixing this problem would involve changing the
|
64
|
-
# legacy_id identifier for each tag which would
|
65
|
-
# break the connection between already-imported tags
|
66
|
-
# and new imports.
|
67
|
-
#
|
68
|
-
id_map[table_name]
|
69
|
-
end
|
70
|
-
|
71
49
|
def prepare_mappings!
|
72
50
|
mappings = []
|
73
51
|
model.reflect_on_all_associations.each do |association|
|
@@ -117,24 +95,24 @@ module AbstractImporter
|
|
117
95
|
end
|
118
96
|
|
119
97
|
def process_record(hash)
|
120
|
-
summary
|
98
|
+
summary.total += 1
|
121
99
|
|
122
100
|
if already_imported?(hash)
|
123
|
-
summary
|
101
|
+
summary.already_imported += 1
|
124
102
|
return
|
125
103
|
end
|
126
104
|
|
127
105
|
remap_foreign_keys!(hash)
|
128
106
|
|
129
107
|
if redundant_record?(hash)
|
130
|
-
summary
|
108
|
+
summary.redundant += 1
|
131
109
|
return
|
132
110
|
end
|
133
111
|
|
134
112
|
if create_record(hash)
|
135
|
-
summary
|
113
|
+
summary.created += 1
|
136
114
|
else
|
137
|
-
summary
|
115
|
+
summary.invalid += 1
|
138
116
|
end
|
139
117
|
end
|
140
118
|
|
@@ -143,7 +121,7 @@ module AbstractImporter
|
|
143
121
|
|
144
122
|
|
145
123
|
def already_imported?(hash)
|
146
|
-
|
124
|
+
id_map.contains? table_name, hash[:id]
|
147
125
|
end
|
148
126
|
|
149
127
|
def remap_foreign_keys!(hash)
|
@@ -43,19 +43,9 @@ module AbstractImporter
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def finish_collection(collection, summary)
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
if summary[0] > 0
|
50
|
-
stat "#{summary[3]} #{collection.name} were imported previously"
|
51
|
-
stat "#{summary[1]} #{collection.name} would create duplicates and will not be imported"
|
52
|
-
stat "#{summary[4]} #{collection.name} were invalid"
|
53
|
-
stat "#{summary[2]} #{collection.name} were imported"
|
54
|
-
end
|
55
|
-
stat "#{elapsed} elapsed" << (summary[0] > 0 ? " (#{(ms / summary[0]).to_i}ms each)" : "")
|
56
|
-
|
57
|
-
print_messages(@notices, "Notices")
|
58
|
-
print_messages(@errors, "Errors")
|
46
|
+
print_summary summary, collection.name
|
47
|
+
print_messages @notices, "Notices"
|
48
|
+
print_messages @errors, "Errors"
|
59
49
|
end
|
60
50
|
|
61
51
|
|
@@ -115,6 +105,19 @@ module AbstractImporter
|
|
115
105
|
end
|
116
106
|
end
|
117
107
|
|
108
|
+
def print_summary(summary, plural)
|
109
|
+
stat "\n #{summary.total} #{plural} were found"
|
110
|
+
if summary.total > 0
|
111
|
+
stat "#{summary.already_imported} #{plural} were imported previously"
|
112
|
+
stat "#{summary.redundant} #{plural} would create duplicates and will not be imported"
|
113
|
+
stat "#{summary.invalid} #{plural} were invalid"
|
114
|
+
stat "#{summary.created} #{plural} were imported"
|
115
|
+
stat "#{distance_of_time(summary.ms)} elapsed (#{(summary.ms / summary.total).to_i}ms each)"
|
116
|
+
else
|
117
|
+
stat "#{distance_of_time(summary.ms)} elapsed"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
118
121
|
def print_messages(array, caption)
|
119
122
|
return if array.empty?
|
120
123
|
status "\n--#{caption}#{("-"*(78-caption.length))}\n\n"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: abstract_importer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bob Lail
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -172,6 +172,7 @@ extensions: []
|
|
172
172
|
extra_rdoc_files: []
|
173
173
|
files:
|
174
174
|
- .gitignore
|
175
|
+
- .travis.yml
|
175
176
|
- Gemfile
|
176
177
|
- LICENSE.txt
|
177
178
|
- README.md
|
@@ -185,6 +186,7 @@ files:
|
|
185
186
|
- lib/abstract_importer/import_options.rb
|
186
187
|
- lib/abstract_importer/import_plan.rb
|
187
188
|
- lib/abstract_importer/reporter.rb
|
189
|
+
- lib/abstract_importer/summary.rb
|
188
190
|
- lib/abstract_importer/version.rb
|
189
191
|
- test/callback_test.rb
|
190
192
|
- test/importer_test.rb
|
@@ -212,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
212
214
|
version: '0'
|
213
215
|
requirements: []
|
214
216
|
rubyforge_project:
|
215
|
-
rubygems_version: 2.0.
|
217
|
+
rubygems_version: 2.0.3
|
216
218
|
signing_key:
|
217
219
|
specification_version: 4
|
218
220
|
summary: Provides services for the mass-import of complex relational data
|