tallty_import_export 1.0.30 → 1.0.35
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tallty_import_export/export.rb +2 -2
- data/lib/tallty_import_export/import.rb +21 -6
- data/lib/tallty_import_export/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: 25de46efb361ea554c4cef13898a6f14ac03e8b56cb5ca7fcbadb72ae40dcfcd
|
4
|
+
data.tar.gz: 0346d65fe26f1c9ee4357aa8b5850a86f9007c5b6da719b8b604a46ef6fe1fea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82b4c135ba29f61e1c1dbd4640b9a8c29639d9ad699474d2a02a11c6db8462269cfe46d9679fc6721258ab2a1b6cbfdc3fb59353de149d21f4cb541b62f206f3
|
7
|
+
data.tar.gz: 54d41b0b50c542827f8350d531aff8dfb80e202b2605cc9dc3cf1d6b49f8764ef7f8b367bf52782a9401c482eb2bd9cf3c684768e73bda935c7c8a8adea5c0cb
|
@@ -141,7 +141,7 @@ module TalltyImportExport
|
|
141
141
|
end
|
142
142
|
|
143
143
|
def process_options options = {}
|
144
|
-
options = export_options.merge(options).with_indifferent_access
|
144
|
+
options = export_options.merge(options.compact_blank!).with_indifferent_access
|
145
145
|
|
146
146
|
@row_height ||= options.delete(:row_height) || 25
|
147
147
|
@width ||= (options.delete(:width) || 20).to_f
|
@@ -157,7 +157,7 @@ module TalltyImportExport
|
|
157
157
|
end
|
158
158
|
|
159
159
|
def export_headers_result
|
160
|
-
@headers ||= export_headers
|
160
|
+
@headers ||= export_headers
|
161
161
|
end
|
162
162
|
|
163
163
|
def export_headers **args
|
@@ -27,7 +27,7 @@ module TalltyImportExport
|
|
27
27
|
|
28
28
|
if TalltyImportExport::Excel === xlsx_file
|
29
29
|
xlsx_file.rows.each_with_excel_hash(@excel_hash) do |line_info|
|
30
|
-
process_line_info(line_info, associations)
|
30
|
+
process_line_info(line_info.with_indifferent_access, associations)
|
31
31
|
end
|
32
32
|
else
|
33
33
|
file_path = xlsx_file.is_a?(String) ? xlsx_file : xlsx_file.path
|
@@ -35,7 +35,7 @@ module TalltyImportExport
|
|
35
35
|
xlsx.each_with_pagename do |_sheetname, sheet|
|
36
36
|
sheet.each(**@excel_hash).with_index do |line_info, index|
|
37
37
|
next if index == 0
|
38
|
-
process_line_info(line_info, associations)
|
38
|
+
process_line_info(line_info.with_indifferent_access, associations)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
@@ -44,7 +44,7 @@ module TalltyImportExport
|
|
44
44
|
def import_data data, associations, **options
|
45
45
|
process_options(options)
|
46
46
|
TalltyImportExport::Excel::Rows.new(data).each_with_excel_hash(@excel_hash) do |line_info|
|
47
|
-
process_line_info(line_info, associations)
|
47
|
+
process_line_info(line_info.with_indifferent_access, associations)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -53,7 +53,7 @@ module TalltyImportExport
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def process_options options
|
56
|
-
options = import_options.merge(options).with_indifferent_access
|
56
|
+
options = import_options.merge(options.compact_blank!).with_indifferent_access
|
57
57
|
@headers = options.delete(:headers) || import_headers
|
58
58
|
@primary_keys = options.delete(:primary_keys) || @headers.map { |header| header[:primary_key] ? header[:key].to_sym : nil }.compact
|
59
59
|
@skip_keys = options.delete(:skip_keys) || @headers.map { |header| header[:skip] ? header[:key].to_sym : nil }.compact
|
@@ -110,8 +110,23 @@ module TalltyImportExport
|
|
110
110
|
true
|
111
111
|
end
|
112
112
|
|
113
|
+
# TODO: 这里,对于import_headers,后面还是不要传参数了
|
114
|
+
# 需要合并proc,前端没有办法把proc传过来
|
113
115
|
def import_headers_result
|
114
|
-
@headers
|
116
|
+
if @headers.present?
|
117
|
+
import_header_hash = import_headers.to_h { |header| [header.with_indifferent_access[:key], header] }.with_indifferent_access
|
118
|
+
@headers.map do |header|
|
119
|
+
key = header[:key]
|
120
|
+
if import_header_hash.dig(key, :proc).present?
|
121
|
+
header[:proc] = import_header_hash.dig(key, :proc)
|
122
|
+
end
|
123
|
+
header
|
124
|
+
end
|
125
|
+
else
|
126
|
+
@headers = import_headers
|
127
|
+
end
|
128
|
+
rescue
|
129
|
+
@headers
|
115
130
|
end
|
116
131
|
|
117
132
|
def import_options
|
@@ -156,7 +171,7 @@ module TalltyImportExport
|
|
156
171
|
_record = associations.find_or_initialize_by(line_info.clone.extract!(*primary_keys))
|
157
172
|
_record.update!(line_info.clone.except!(*primary_keys, *@skip_keys))
|
158
173
|
else
|
159
|
-
associations.create!(line_info)
|
174
|
+
associations.create!(line_info.clone.except!(*@skip_keys))
|
160
175
|
end
|
161
176
|
end
|
162
177
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tallty_import_export
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.35
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- liyijie
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zip-zip
|