tallty_import_export 1.0.3 → 1.0.9
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/common.rb +2 -2
- data/lib/tallty_import_export/export.rb +2 -1
- data/lib/tallty_import_export/import.rb +31 -31
- data/lib/tallty_import_export/version.rb +1 -1
- data/tallty_import_export-1.0.3.gem +0 -0
- data/tallty_import_export-1.0.5.gem +0 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8caa796932bff10fefba6f63f2d084488b1fcb2dd102f7fb1d3d8c84b4500244
|
4
|
+
data.tar.gz: c46cdba654ab877946f7810d6d634c0ba326b882d9b177fba7dd17ed1b4350d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d22ead9b9e98e6d2e23672bddcc2b187bea2287f2702c9b83a8bb3e32dc249c4e11d655b7bd2b2c68954bea7998ec4ff80e555ed93b5de8f7467fded4e2508c
|
7
|
+
data.tar.gz: efc7da3bd4d17e2878fb2721948ccfabbbdb16b91981982be07b33f8165aa56e8b66dfb61e3242abb1773507bebd7b18cdfa891b601b55a64c3cc4356f586b5d
|
@@ -6,14 +6,14 @@ module TalltyImportExport
|
|
6
6
|
end
|
7
7
|
|
8
8
|
module ClassMethods
|
9
|
-
def model_headers
|
9
|
+
def model_headers **args
|
10
10
|
columns.map do |column|
|
11
11
|
{
|
12
12
|
key: column.name,
|
13
13
|
name: column.comment || column.name,
|
14
14
|
attr_type: column.type,
|
15
15
|
format: column.type == :string ? :string : nil,
|
16
|
-
primary_key: column.name == 'id' ? true : false
|
16
|
+
primary_key: column.name == 'id' ? true : false
|
17
17
|
}
|
18
18
|
end
|
19
19
|
end
|
@@ -26,6 +26,7 @@ module TalltyImportExport
|
|
26
26
|
# chain: 导出时对象属性通过链式调用
|
27
27
|
# index: 数组方式,需要嵌套拿到里面的
|
28
28
|
# merge: true/false,默认false,某一列,如果上下行的内容相同,则直接合并单元格
|
29
|
+
# json: model_payload,代表存储在某一个列中
|
29
30
|
|
30
31
|
def export_xlsx records, **options
|
31
32
|
records = with_scope records
|
@@ -138,7 +139,7 @@ module TalltyImportExport
|
|
138
139
|
@headers || export_headers
|
139
140
|
end
|
140
141
|
|
141
|
-
def export_headers
|
142
|
+
def export_headers **args
|
142
143
|
@headers || klass.try(:headers) || klass.try(:model_headers)
|
143
144
|
end
|
144
145
|
|
@@ -1,11 +1,10 @@
|
|
1
1
|
module TalltyImportExport
|
2
2
|
class Import
|
3
3
|
require 'roo'
|
4
|
-
attr_reader :klass, :context, :
|
4
|
+
attr_reader :klass, :context, :primary_keys, :associations
|
5
5
|
|
6
6
|
def initialize klass
|
7
7
|
@klass = klass
|
8
|
-
@headers = import_headers_result.map { |header| header.with_indifferent_access }
|
9
8
|
@context = Context.new({})
|
10
9
|
end
|
11
10
|
|
@@ -15,6 +14,7 @@ module TalltyImportExport
|
|
15
14
|
# format: excel是否需要特定的格式,目前主要是类似于身份证号,可以用string
|
16
15
|
# convert: 导入时候,把excel的内容转换成导入时候代码逻辑需要的内容
|
17
16
|
# primary_key: 是否是主键
|
17
|
+
# json: model_payload,代表存储在某一个列中
|
18
18
|
|
19
19
|
# xlsx_file 为 file path or file object or TalltyImportExport::Excel.new
|
20
20
|
def import_xlsx xlsx_file, associations, **options
|
@@ -51,10 +51,10 @@ module TalltyImportExport
|
|
51
51
|
|
52
52
|
def process_options options
|
53
53
|
options = options.with_indifferent_access
|
54
|
-
|
55
|
-
@primary_keys = options.delete(:primary_keys) || headers.map { |header| header[:primary_key] ? header[:key].to_sym : nil }.compact
|
54
|
+
@headers = options.delete(:headers)
|
55
|
+
@primary_keys = options.delete(:primary_keys) || @headers.map { |header| header[:primary_key] ? header[:key].to_sym : nil }.compact
|
56
56
|
|
57
|
-
@excel_hash = headers.reduce({}) do |h, header|
|
57
|
+
@excel_hash = @headers.reduce({}) do |h, header|
|
58
58
|
h[header[:key].to_sym] = header[:name]
|
59
59
|
h
|
60
60
|
end
|
@@ -75,7 +75,7 @@ module TalltyImportExport
|
|
75
75
|
|
76
76
|
def convert_data line_info
|
77
77
|
line_info.with_indifferent_access.reduce({}) do |h, (k, v)|
|
78
|
-
header = headers.find do |_header|
|
78
|
+
header = @headers.find do |_header|
|
79
79
|
_header[:key].to_sym == k.to_sym
|
80
80
|
end
|
81
81
|
# header[:convert] = handle_xxx
|
@@ -100,33 +100,33 @@ module TalltyImportExport
|
|
100
100
|
@headers || import_headers
|
101
101
|
end
|
102
102
|
|
103
|
-
def import_headers
|
104
|
-
@headers || klass.try(:
|
103
|
+
def import_headers **args
|
104
|
+
@headers || klass.try(:headers) || klass.try(:model_headers) || (raise ArgumentError.new('missing import_headers'))
|
105
105
|
end
|
106
106
|
|
107
|
-
# 只保留 key, name, json, 合并到 import_header
|
108
|
-
def headers= val
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
end
|
107
|
+
# # 只保留 key, name, json, 合并到 import_header
|
108
|
+
# def headers= val
|
109
|
+
# if val.empty?
|
110
|
+
# @headers = import_headers_result.map { |header| header.with_indifferent_access }
|
111
|
+
# return
|
112
|
+
# end
|
113
|
+
#
|
114
|
+
# key_to_coming_header = val.reduce({}) do |out, header|
|
115
|
+
# out[header.with_indifferent_access[:key].to_sym] = header.with_indifferent_access
|
116
|
+
# out
|
117
|
+
# end
|
118
|
+
#
|
119
|
+
# result = []
|
120
|
+
# val.map do |header|
|
121
|
+
# if (exist_header = import_headers_result.find { |model_header| model_header[:key] === header[:key] })
|
122
|
+
# result.push(exist_header.merge(header.compact))
|
123
|
+
# else
|
124
|
+
# result.push(header)
|
125
|
+
# end
|
126
|
+
# end
|
127
|
+
#
|
128
|
+
# @headers = result
|
129
|
+
# end
|
130
130
|
|
131
131
|
def skip val, processing_line_info, raw_line_info
|
132
132
|
# do nothing there, use for header[:convert]
|
Binary file
|
Binary file
|
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.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- liyijie
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-05-
|
11
|
+
date: 2021-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zip-zip
|
@@ -149,6 +149,8 @@ files:
|
|
149
149
|
- lib/tallty_import_export/import.rb
|
150
150
|
- lib/tallty_import_export/importable.rb
|
151
151
|
- lib/tallty_import_export/version.rb
|
152
|
+
- tallty_import_export-1.0.3.gem
|
153
|
+
- tallty_import_export-1.0.5.gem
|
152
154
|
- tallty_import_export.gemspec
|
153
155
|
homepage: https://git.tallty.com/open-source/tallty_import_export
|
154
156
|
licenses:
|