Commit 631eeccf by liyijie

feat: 增加import_options 和 export_options,另外 export 支持 each_method

parent 3e08e5e9
PATH
remote: .
specs:
tallty_import_export (1.0.22)
tallty_import_export (1.0.24)
activesupport
caxlsx
redis
......@@ -22,7 +22,7 @@ GEM
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
caxlsx (3.1.0)
caxlsx (3.1.1)
htmlentities (~> 4.3, >= 4.3.4)
marcel (~> 1.0)
nokogiri (~> 1.10, >= 1.10.4)
......@@ -32,7 +32,7 @@ GEM
htmlentities (4.3.4)
i18n (1.8.10)
concurrent-ruby (~> 1.0)
marcel (1.0.1)
marcel (1.0.2)
mini_portile2 (2.6.1)
minitest (5.14.4)
nokogiri (1.12.4)
......@@ -65,7 +65,7 @@ GEM
rspec-support (3.10.0)
ruby-ole (1.2.12.2)
rubyzip (2.3.2)
spreadsheet (1.2.9)
spreadsheet (1.3.0)
ruby-ole
tallty_duck_record (1.1.3)
activemodel (>= 5.0)
......
......@@ -89,7 +89,7 @@ module TalltyImportExport
merge_column_hash = {}
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|
row = []
headers.each_with_index do |header, col_index|
......@@ -123,8 +123,13 @@ module TalltyImportExport
end
end
# 地处整体配置信息
def export_options
{}
end
def process_options options = {}
options = options.with_indifferent_access
options = export_options.merge(options).with_indifferent_access
@row_height ||= options.delete(:row_height) || 25
@width ||= (options.delete(:width) || 20).to_f
......@@ -132,6 +137,7 @@ module TalltyImportExport
@group_by ||= options.delete(:group_by)
@group_where = "#{@group_by}_eq" if @group_by.present?
@headers ||= options.delete(:headers)
@each_method ||= options.delete(:each_method)
end
def with_scope records
......
......@@ -51,7 +51,7 @@ module TalltyImportExport
end
def process_options options
options = options.with_indifferent_access
options = import_options.merge(options).with_indifferent_access
@headers = options.delete(:headers) || import_headers
@primary_keys = options.delete(:primary_keys) || @headers.map { |header| header[:primary_key] ? header[:key].to_sym : nil }.compact
@params = options
......@@ -107,6 +107,10 @@ module TalltyImportExport
@headers ||= import_headers&.with_indifferent_access
end
def import_options
{}
end
def import_headers **args
@headers || klass.try(:headers) || klass.try(:model_headers) || (raise ArgumentError.new('missing import_headers'))
end
......
module TalltyImportExport
VERSION = "1.0.24"
VERSION = "1.0.25"
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment