csv_step_importer 0.11.0 → 0.11.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/README.md +4 -0
- data/lib/csv_step_importer/loader.rb +1 -1
- data/lib/csv_step_importer/model/dao.rb +2 -2
- data/lib/csv_step_importer/model/model.rb +7 -7
- data/lib/csv_step_importer/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 340c82c7b6f4e56a0092d5044971b9a2aa6e66739a045162afc0e12bf5da3345
|
4
|
+
data.tar.gz: 8691cb1d2f8402598b62210d20c742e6d1246a97915e2fd5a81bbbe9c5a7736a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 147a95d14716f92967a5059f6202e992b2a9f4a3316cf139cd11d02a669ea449051c2b2a61447e63c66cfd763957041a8c212e5edab72d419ef6628569fae0ed
|
7
|
+
data.tar.gz: 771576acb65c952f7837a9c9fed7bbb3444e06918d4a3384e06644a17f664f38450acc8f3ee1124ae87706c32de3813adc3c24637da221291d352dbf86556a41
|
data/CHANGELOG.md
CHANGED
@@ -129,3 +129,8 @@ See lib/csv_step_importer/file.rb for more options
|
|
129
129
|
|
130
130
|
- ImportableModel's finder_keys method now defaults to composite_key_columns
|
131
131
|
- ImportableModel's Importer (uses ActiveRecord::Import) now raises an exception if the import fails
|
132
|
+
|
133
|
+
## 2018-09-11 Version 0.11.1
|
134
|
+
### Added
|
135
|
+
### Changed
|
136
|
+
- Fixed `composite_key_columns` filter functionality
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -7,6 +7,10 @@ It depends on
|
|
7
7
|
- [zdennis/activerecord-import](https://github.com/zdennis/activerecord-import)
|
8
8
|
- [GitHub - tilo/smarter_csv](https://github.com/tilo/smarter_csv)
|
9
9
|
|
10
|
+
## Sample Application (Thanks to @vochicong)
|
11
|
+
|
12
|
+
[vochicong/csv_step_importer_sample](https://github.com/vochicong/csv_step_importer_sample)
|
13
|
+
|
10
14
|
## Installation
|
11
15
|
|
12
16
|
Add this line to your application's Gemfile:
|
@@ -6,7 +6,7 @@ module CSVStepImporter
|
|
6
6
|
class Loader < CSVStepImporter::Node
|
7
7
|
def initialize(file_class: CSVStepImporter::File, chunk_class: CSVStepImporter::Chunk, **attributes)
|
8
8
|
super **attributes.slice(:parent, :children, :env)
|
9
|
-
add_children attributes[:path] ? file_class.new(
|
9
|
+
add_children attributes[:path] ? file_class.new(**attributes.merge!(chunk_class: chunk_class)) : chunk_class.new(**attributes)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -60,7 +60,7 @@ module CSVStepImporter
|
|
60
60
|
end
|
61
61
|
|
62
62
|
# retrieve a dao for a different model using the same CSV row. This is useful e.g. if you use the reflector to get ids of related data
|
63
|
-
def dao_for
|
63
|
+
def dao_for(model:, pluralize: false)
|
64
64
|
row.cache[model.cache_key(pluralize: pluralize)]
|
65
65
|
end
|
66
66
|
|
@@ -74,7 +74,7 @@ module CSVStepImporter
|
|
74
74
|
end
|
75
75
|
|
76
76
|
# unlink this dao from the row and replace it with a different dao
|
77
|
-
def unlink!
|
77
|
+
def unlink!(replace_with: nil)
|
78
78
|
cached_daos = row.cache[model.cache_key(pluralize: true)]
|
79
79
|
|
80
80
|
# remove from cache with pluralized key
|
@@ -21,8 +21,8 @@ module CSVStepImporter
|
|
21
21
|
# Configuration
|
22
22
|
#########################################################
|
23
23
|
|
24
|
-
def self.cache_key
|
25
|
-
key = name.underscore.gsub(
|
24
|
+
def self.cache_key(pluralize: false)
|
25
|
+
key = name.underscore.gsub("/", "_")
|
26
26
|
(pluralize ? key.pluralize : key.singularize).to_sym
|
27
27
|
end
|
28
28
|
|
@@ -79,14 +79,14 @@ module CSVStepImporter
|
|
79
79
|
def filter_daos!
|
80
80
|
unique_daos = {}
|
81
81
|
|
82
|
-
daos.
|
83
|
-
hash = dao.value.slice(composite_key_columns).hash
|
84
|
-
|
82
|
+
daos.keep_if do |dao|
|
83
|
+
hash = dao.value.slice(*composite_key_columns).hash
|
84
|
+
keep = (unique_daos[hash] ||= dao) == dao
|
85
85
|
|
86
86
|
# unlink to be deleted dao and add a link to
|
87
|
-
dao.unlink! replace_with: unique_daos[hash] unless
|
87
|
+
dao.unlink! replace_with: unique_daos[hash] unless keep
|
88
88
|
|
89
|
-
|
89
|
+
keep
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|