tallty_import_export 1.0.3 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01a93e8f64b1aac7a0795ef697fe6fe27f084edc4570805e0bc8000750f3c611
|
4
|
+
data.tar.gz: 7ee6334bd719ec319f25f64a07c38d88a9073926de5c379cf75483655195aa8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b70babba1dcec1b39c0ec311f44b51bf5a41268fc301f365099b960d292e4b6812cf6917acee757c24744db671e66494ced0f2eea457c5f8e8d7e934deff0b60
|
7
|
+
data.tar.gz: 6ecac3c336068b4331e9fb3525c902f38f70bd0f0a1bfd73209ced1b357a1ad076a660349cdacf51492e5be07e909df77996a2e78435afec0751cee82ad8068c
|
@@ -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
|
@@ -100,8 +100,8 @@ 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
107
|
# 只保留 key, name, json, 合并到 import_header
|
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.5
|
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-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zip-zip
|
@@ -149,6 +149,7 @@ 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
|
152
153
|
- tallty_import_export.gemspec
|
153
154
|
homepage: https://git.tallty.com/open-source/tallty_import_export
|
154
155
|
licenses:
|