ntq_excelsior 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +31 -1
- data/lib/ntq_excelsior/importer.rb +31 -1
- data/lib/ntq_excelsior/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5a967c15c3f10e6a7e22795e99b73d9be8e2ba2c98ea756672f587bf2c0c348
|
4
|
+
data.tar.gz: 6a90997fc04c6a6b7a45cc38d27be78be86266c90dec229427fb71f72f556adc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d26fe0bd71a850e06cc17941700c4d9b0abe6f1b7d329d3bc74e872b1cd138f359d8357a98e67278f63be585073ae46dc3e70de83dde800a5bf5cc22073960fa
|
7
|
+
data.tar.gz: be8aa18475f1a4520ca5ad4aa22eb6b06bb98c564a6ef7c26d35a95b8650055e5bddc745a5ba24684f95ffc6288157d37a288ed9be6d076ede64f2337ac6acf1
|
data/README.md
CHANGED
@@ -89,7 +89,37 @@ class UserImporter < NtqExcelsior::Importer
|
|
89
89
|
|
90
90
|
model_klass "User"
|
91
91
|
|
92
|
-
primary_key :
|
92
|
+
primary_key :email
|
93
|
+
|
94
|
+
# autosave false
|
95
|
+
|
96
|
+
structure [{
|
97
|
+
header: "Email",
|
98
|
+
description: "Email de l'utilisateur a créer ou modifier",
|
99
|
+
required: true,
|
100
|
+
},
|
101
|
+
{
|
102
|
+
header: "Actif",
|
103
|
+
description: "Utilisateur activé",
|
104
|
+
required: true,
|
105
|
+
values: [
|
106
|
+
{
|
107
|
+
header: "True",
|
108
|
+
description: "Activé",
|
109
|
+
}, {
|
110
|
+
header: "False",
|
111
|
+
description: "Inactivé",
|
112
|
+
}
|
113
|
+
]
|
114
|
+
}, {
|
115
|
+
header: "Prénom",
|
116
|
+
required: true,
|
117
|
+
}, {
|
118
|
+
header: "Nom",
|
119
|
+
required: true,
|
120
|
+
}]
|
121
|
+
|
122
|
+
sample_file "/import_samples/users.xlsx"
|
93
123
|
|
94
124
|
schema({
|
95
125
|
email: 'Email',
|
@@ -11,6 +11,10 @@ module NtqExcelsior
|
|
11
11
|
@autosave ||= value
|
12
12
|
end
|
13
13
|
|
14
|
+
def autoset(value = nil)
|
15
|
+
@autoset ||= value
|
16
|
+
end
|
17
|
+
|
14
18
|
def spreadsheet_options(value = nil)
|
15
19
|
@spreadsheet_options ||= value
|
16
20
|
end
|
@@ -115,7 +119,29 @@ module NtqExcelsior
|
|
115
119
|
def find_or_initialize_record(line)
|
116
120
|
return nil unless self.class.primary_key && self.class.model_klass
|
117
121
|
|
118
|
-
|
122
|
+
if line[self.class.primary_key.to_sym].present?
|
123
|
+
if self.class.primary_key.to_sym == :id
|
124
|
+
record = self.class.model_klass.constantize.find_by id: line[self.class.primary_key.to_sym]
|
125
|
+
else
|
126
|
+
record = self.class.model_klass.constantize.find_or_initialize_by("#{self.class.primary_key}": line[self.class.primary_key.to_sym])
|
127
|
+
end
|
128
|
+
end
|
129
|
+
record = self.class.model_klass.constantize.new unless record
|
130
|
+
record
|
131
|
+
end
|
132
|
+
|
133
|
+
def record_attributes(record)
|
134
|
+
return @record_attributes if @record_attributes
|
135
|
+
|
136
|
+
@record_attributes = self.class.schema.keys.select{|k| k.to_sym != :id && record.respond_to?(:"#{k}=") }
|
137
|
+
end
|
138
|
+
|
139
|
+
def set_record_fields(record, line)
|
140
|
+
attributes_to_set = record_attributes(record)
|
141
|
+
attributes_to_set.each do |attribute|
|
142
|
+
record.send(:"#{attribute}=", line[attribute])
|
143
|
+
end
|
144
|
+
record
|
119
145
|
end
|
120
146
|
|
121
147
|
def import_line(line, save: true)
|
@@ -123,6 +149,10 @@ module NtqExcelsior
|
|
123
149
|
@success = false
|
124
150
|
@action = nil
|
125
151
|
@errors = []
|
152
|
+
|
153
|
+
if (!self.class.autoset.nil? || self.class.autoset)
|
154
|
+
record = set_record_fields(record, line)
|
155
|
+
end
|
126
156
|
|
127
157
|
yield(record, line) if block_given?
|
128
158
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ntq_excelsior
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: caxlsx
|