csv_step_importer 0.3.1 → 0.4.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4101e937149c860c8321d7f620c5108ce505ba6de6bb37602b59405e08ae0d9c
|
4
|
+
data.tar.gz: 5c739f6d4cb08a19d11e12618e4844bad5b90a66fe785fc5366142230cb6e90e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d231814e8ce5bbd30f664a52bcde75ff192b03d2cfbd338e1bdb70ed72025b939c43165d6b9a3afef5de9d9a31dfe917e149c5f9db77249dbc4098afeda30900
|
7
|
+
data.tar.gz: 5f2f9d7ebebf2c0ffd73106a7fd658a22a0a95d9440202a0769e0ce3f635546ab51c6664cee8f76c490c85c0d402921941363cf30c2427d64dfc87b558b30bc9
|
@@ -31,7 +31,8 @@ module CSVStepImporter
|
|
31
31
|
end
|
32
32
|
|
33
33
|
# example [:email, :updated_at]
|
34
|
-
|
34
|
+
# see: https://github.com/zdennis/activerecord-import/wiki/On-Duplicate-Key-Update
|
35
|
+
def on_duplicate_key_update
|
35
36
|
raise "please extend and implement"
|
36
37
|
end
|
37
38
|
|
@@ -5,18 +5,16 @@ module CSVStepImporter
|
|
5
5
|
class Importer < CSVStepImporter::Node
|
6
6
|
attr_accessor :dao_values
|
7
7
|
|
8
|
-
validate :validate_updatable_columns, unless: -> { updatable_columns.any? { |column| column.is_a?(Hash) } }
|
9
|
-
|
10
8
|
delegate :model_class, to: :parent
|
11
9
|
delegate :columns, to: :parent
|
12
|
-
delegate :
|
10
|
+
delegate :on_duplicate_key_update, to: :parent
|
13
11
|
delegate :dao_values, to: :parent
|
14
12
|
|
15
13
|
def create_or_update
|
16
14
|
model_class.import(
|
17
15
|
columns,
|
18
16
|
dao_values,
|
19
|
-
on_duplicate_key_update:
|
17
|
+
on_duplicate_key_update: on_duplicate_key_update,
|
20
18
|
validate: false,
|
21
19
|
timestamps: false,
|
22
20
|
)
|
@@ -28,14 +26,6 @@ module CSVStepImporter
|
|
28
26
|
self.values = values
|
29
27
|
save!
|
30
28
|
end
|
31
|
-
|
32
|
-
def validate_updatable_columns
|
33
|
-
return unless errors.empty?
|
34
|
-
|
35
|
-
if (updatable_columns - columns).present?
|
36
|
-
errors[:updatable_columns] << "updatable_columns must be subset of columns"
|
37
|
-
end
|
38
|
-
end
|
39
29
|
end
|
40
30
|
end
|
41
31
|
end
|