imp_exp 1.0.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/services/imp_exp/importers/base.rb +4 -1
- data/app/services/imp_exp/models/base.rb +19 -15
- data/config/locales/fr.yml +1 -1
- data/lib/imp_exp/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7f2b63cfa24b1f1d1b210c163843a6fda15a4eee82fd8f875e3944f438bb0ec
|
4
|
+
data.tar.gz: d42e8694afc0653e5c9f9a7a4e9345bb1375e515a4c97b28100b8109f7aa78d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05ad19e47c62b9fa6b0cf2a2522215c4e6bed74955c243788ef2745e4f97809db4fb3f89c8b75c6dd8dd5b8f8331a77676c38899ad1e4c8b5d5b314b852b7482
|
7
|
+
data.tar.gz: cc8de48c25302a940800a8095c9ce03f2eb913e2d7ee0a9782828c9927d9ffbbb9c37a2b8d973b60e0ccc910ff24a34c784b4aa4f34e33b4e4306a37cc7e625d
|
@@ -50,7 +50,7 @@ module ImpExp
|
|
50
50
|
{ imported: imported, import_errors: errors }
|
51
51
|
end
|
52
52
|
|
53
|
-
def import_model_data(model, model_data, files_directory_path)
|
53
|
+
def import_model_data(model, model_data, files_directory_path) # rubocop:disable Metrics/MethodLength
|
54
54
|
model_data.each_with_index do |row, i|
|
55
55
|
line = ROW_OFFSET + i + 1
|
56
56
|
model_name = model.model_name
|
@@ -76,6 +76,7 @@ module ImpExp
|
|
76
76
|
attach_files(record, files_directory_path, model, row, line) if files_directory_path.present?
|
77
77
|
|
78
78
|
if record.save(context: :import)
|
79
|
+
after_save(record)
|
79
80
|
@imported[model.model_name] += 1
|
80
81
|
next
|
81
82
|
end
|
@@ -86,6 +87,8 @@ module ImpExp
|
|
86
87
|
|
87
88
|
private
|
88
89
|
|
90
|
+
def after_save(_record); end
|
91
|
+
|
89
92
|
def raise_rescued_standard_error?
|
90
93
|
Rails.env.test? || Rails.env.development?
|
91
94
|
end
|
@@ -99,25 +99,29 @@ module ImpExp
|
|
99
99
|
def rows(scoping_parent)
|
100
100
|
rows = []
|
101
101
|
preload_associations(order(scoped(scoping_parent))).each do |record|
|
102
|
-
|
103
|
-
attribute_names.each do |attribute_name|
|
104
|
-
serializer = attribute_options(attribute_name)[:serializer]
|
105
|
-
data[attribute_name] = serializer.dump(record, attribute_name) if serializer
|
106
|
-
end
|
107
|
-
data = data.values
|
108
|
-
relation_names.each do |relation_name|
|
109
|
-
serializer = relation_options(relation_name)[:serializer]
|
110
|
-
data << serializer.dump(record, relation_name)
|
111
|
-
end
|
112
|
-
data.concat(file_attribute_names.map do |file_attribute_name|
|
113
|
-
file = record.send(file_attribute_name)
|
114
|
-
"#{files_directory_path}/#{filename(file)}" if file.attached?
|
115
|
-
end)
|
116
|
-
rows << data
|
102
|
+
rows << row(record)
|
117
103
|
end
|
118
104
|
rows
|
119
105
|
end
|
120
106
|
|
107
|
+
def row(record)
|
108
|
+
data = record.slice(attribute_names)
|
109
|
+
attribute_names.each do |attribute_name|
|
110
|
+
serializer = attribute_options(attribute_name)[:serializer]
|
111
|
+
data[attribute_name] = serializer.dump(record, attribute_name) if serializer
|
112
|
+
end
|
113
|
+
data = data.values
|
114
|
+
relation_names.each do |relation_name|
|
115
|
+
serializer = relation_options(relation_name)[:serializer]
|
116
|
+
data << serializer.dump(record, relation_name)
|
117
|
+
end
|
118
|
+
data.concat(file_attribute_names.map do |file_attribute_name|
|
119
|
+
file = record.send(file_attribute_name)
|
120
|
+
"#{files_directory_path}/#{filename(file)}" if file.attached?
|
121
|
+
end)
|
122
|
+
data
|
123
|
+
end
|
124
|
+
|
121
125
|
def files(scoping_parent)
|
122
126
|
scoped(scoping_parent).flat_map do |record|
|
123
127
|
record.slice(file_attribute_names).values.select(&:attached?)
|
data/config/locales/fr.yml
CHANGED
@@ -7,4 +7,4 @@ fr:
|
|
7
7
|
wrong_format: "Erreur de format : %{message}."
|
8
8
|
model_errors: "Feuille %{model_name} - Ligne %{line} : %{messages}"
|
9
9
|
data_validation_error: "Feuille %{model_name} - Ligne %{line} - Colonne \"%{column}\" : valeur \"%{value}\" incorrecte, valeur attendue : %{expected}"
|
10
|
-
file_not_found: "Fichier %{file_path} non trouvé."
|
10
|
+
file_not_found: "Fichier %{file_path} non trouvé."
|
data/lib/imp_exp/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imp_exp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Dev team Nerya
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: caxlsx
|
@@ -69,7 +69,7 @@ dependencies:
|
|
69
69
|
description: Import data from xlsx into a rails app and export data to xlsx from a
|
70
70
|
rails app
|
71
71
|
email:
|
72
|
-
-
|
72
|
+
- dev@nerya.fr
|
73
73
|
executables: []
|
74
74
|
extensions: []
|
75
75
|
extra_rdoc_files: []
|
@@ -122,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
122
|
- !ruby/object:Gem::Version
|
123
123
|
version: '0'
|
124
124
|
requirements: []
|
125
|
-
rubygems_version: 3.4.
|
125
|
+
rubygems_version: 3.4.19
|
126
126
|
signing_key:
|
127
127
|
specification_version: 4
|
128
128
|
summary: Import data from xlsx into a rails app and export data to xlsx from a rails
|