Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tallty_import_export
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
tallty_import_export
Commits
631eeccf
Commit
631eeccf
authored
Nov 08, 2021
by
liyijie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 增加import_options 和 export_options,另外 export 支持 each_method
parent
3e08e5e9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
8 deletions
+18
-8
Gemfile.lock
Gemfile.lock
+4
-4
export.rb
lib/tallty_import_export/export.rb
+8
-2
import.rb
lib/tallty_import_export/import.rb
+5
-1
version.rb
lib/tallty_import_export/version.rb
+1
-1
No files found.
Gemfile.lock
View file @
631eeccf
PATH
PATH
remote: .
remote: .
specs:
specs:
tallty_import_export (1.0.2
2
)
tallty_import_export (1.0.2
4
)
activesupport
activesupport
caxlsx
caxlsx
redis
redis
...
@@ -22,7 +22,7 @@ GEM
...
@@ -22,7 +22,7 @@ GEM
minitest (>= 5.1)
minitest (>= 5.1)
tzinfo (~> 2.0)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
zeitwerk (~> 2.3)
caxlsx (3.1.
0
)
caxlsx (3.1.
1
)
htmlentities (~> 4.3, >= 4.3.4)
htmlentities (~> 4.3, >= 4.3.4)
marcel (~> 1.0)
marcel (~> 1.0)
nokogiri (~> 1.10, >= 1.10.4)
nokogiri (~> 1.10, >= 1.10.4)
...
@@ -32,7 +32,7 @@ GEM
...
@@ -32,7 +32,7 @@ GEM
htmlentities (4.3.4)
htmlentities (4.3.4)
i18n (1.8.10)
i18n (1.8.10)
concurrent-ruby (~> 1.0)
concurrent-ruby (~> 1.0)
marcel (1.0.
1
)
marcel (1.0.
2
)
mini_portile2 (2.6.1)
mini_portile2 (2.6.1)
minitest (5.14.4)
minitest (5.14.4)
nokogiri (1.12.4)
nokogiri (1.12.4)
...
@@ -65,7 +65,7 @@ GEM
...
@@ -65,7 +65,7 @@ GEM
rspec-support (3.10.0)
rspec-support (3.10.0)
ruby-ole (1.2.12.2)
ruby-ole (1.2.12.2)
rubyzip (2.3.2)
rubyzip (2.3.2)
spreadsheet (1.
2.9
)
spreadsheet (1.
3.0
)
ruby-ole
ruby-ole
tallty_duck_record (1.1.3)
tallty_duck_record (1.1.3)
activemodel (>= 5.0)
activemodel (>= 5.0)
...
...
lib/tallty_import_export/export.rb
View file @
631eeccf
...
@@ -89,7 +89,7 @@ module TalltyImportExport
...
@@ -89,7 +89,7 @@ module TalltyImportExport
merge_column_hash
=
{}
merge_column_hash
=
{}
first_content_row_index
=
respond_to?
(
:first_header
)
?
2
:
1
first_content_row_index
=
respond_to?
(
:first_header
)
?
2
:
1
each_method
=
records
.
is_a?
(
Array
)
?
:
each
:
:each
each_method
=
@each_method
||
:each
records
.
send
(
each_method
).
with_index
do
|
record
,
index
|
records
.
send
(
each_method
).
with_index
do
|
record
,
index
|
row
=
[]
row
=
[]
headers
.
each_with_index
do
|
header
,
col_index
|
headers
.
each_with_index
do
|
header
,
col_index
|
...
@@ -123,8 +123,13 @@ module TalltyImportExport
...
@@ -123,8 +123,13 @@ module TalltyImportExport
end
end
end
end
# 地处整体配置信息
def
export_options
{}
end
def
process_options
options
=
{}
def
process_options
options
=
{}
options
=
options
.
with_indifferent_access
options
=
export_options
.
merge
(
options
)
.
with_indifferent_access
@row_height
||=
options
.
delete
(
:row_height
)
||
25
@row_height
||=
options
.
delete
(
:row_height
)
||
25
@width
||=
(
options
.
delete
(
:width
)
||
20
).
to_f
@width
||=
(
options
.
delete
(
:width
)
||
20
).
to_f
...
@@ -132,6 +137,7 @@ module TalltyImportExport
...
@@ -132,6 +137,7 @@ module TalltyImportExport
@group_by
||=
options
.
delete
(
:group_by
)
@group_by
||=
options
.
delete
(
:group_by
)
@group_where
=
"
#{
@group_by
}
_eq"
if
@group_by
.
present?
@group_where
=
"
#{
@group_by
}
_eq"
if
@group_by
.
present?
@headers
||=
options
.
delete
(
:headers
)
@headers
||=
options
.
delete
(
:headers
)
@each_method
||=
options
.
delete
(
:each_method
)
end
end
def
with_scope
records
def
with_scope
records
...
...
lib/tallty_import_export/import.rb
View file @
631eeccf
...
@@ -51,7 +51,7 @@ module TalltyImportExport
...
@@ -51,7 +51,7 @@ module TalltyImportExport
end
end
def
process_options
options
def
process_options
options
options
=
options
.
with_indifferent_access
options
=
import_options
.
merge
(
options
)
.
with_indifferent_access
@headers
=
options
.
delete
(
:headers
)
||
import_headers
@headers
=
options
.
delete
(
:headers
)
||
import_headers
@primary_keys
=
options
.
delete
(
:primary_keys
)
||
@headers
.
map
{
|
header
|
header
[
:primary_key
]
?
header
[:
key
].
to_sym
:
nil
}.
compact
@primary_keys
=
options
.
delete
(
:primary_keys
)
||
@headers
.
map
{
|
header
|
header
[
:primary_key
]
?
header
[:
key
].
to_sym
:
nil
}.
compact
@params
=
options
@params
=
options
...
@@ -107,6 +107,10 @@ module TalltyImportExport
...
@@ -107,6 +107,10 @@ module TalltyImportExport
@headers
||=
import_headers
&
.
with_indifferent_access
@headers
||=
import_headers
&
.
with_indifferent_access
end
end
def
import_options
{}
end
def
import_headers
**
args
def
import_headers
**
args
@headers
||
klass
.
try
(
:headers
)
||
klass
.
try
(
:model_headers
)
||
(
raise
ArgumentError
.
new
(
'missing import_headers'
))
@headers
||
klass
.
try
(
:headers
)
||
klass
.
try
(
:model_headers
)
||
(
raise
ArgumentError
.
new
(
'missing import_headers'
))
end
end
...
...
lib/tallty_import_export/version.rb
View file @
631eeccf
module
TalltyImportExport
module
TalltyImportExport
VERSION
=
"1.0.2
4
"
VERSION
=
"1.0.2
5
"
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment