Commit b4f484ea by liyijie

fix: support json with prefix try_method

parent 9c6b1aa0
...@@ -189,12 +189,10 @@ module TalltyImportExport ...@@ -189,12 +189,10 @@ module TalltyImportExport
send(header[:method], record, header) send(header[:method], record, header)
elsif header[:chain].present? elsif header[:chain].present?
try_chain(record, header[:chain]) try_chain(record, header[:chain])
elsif header[:json]
record.send(header[:json])[header[:key]]
elsif header[:proc] && header[:proc].respond_to?(:call) elsif header[:proc] && header[:proc].respond_to?(:call)
header[:proc].call(record, context) header[:proc].call(record, context)
else else
try_method(record, header[:key]) try_method(record, header[:key], prefix: header[:json])
end end
data = handle_format(data, header) data = handle_format(data, header)
data = handle_data_type(data) data = handle_data_type(data)
...@@ -207,9 +205,10 @@ module TalltyImportExport ...@@ -207,9 +205,10 @@ module TalltyImportExport
arr.reduce(record) { |r, m| r.try(:[], m) || r.try(:[], m.to_sym) || r.try(m) } arr.reduce(record) { |r, m| r.try(:[], m) || r.try(:[], m.to_sym) || r.try(m) }
end end
def try_method record, method def try_method record, method, prefix: nil
arr = method.to_s.split(/\./) arr = method.to_s.split(/\./)
try_chain record, arr prefix_arr = prefix.to_s.split(/\./)
try_chain record, arr + arr1
end end
# 根据数据类型 attr_type 进行数据的格式化 # 根据数据类型 attr_type 进行数据的格式化
......
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