Commit b71d8bd6 by liyijie

fix: try_chain support association

parent 9c1d7c23
...@@ -240,8 +240,9 @@ module TalltyImportExport ...@@ -240,8 +240,9 @@ module TalltyImportExport
def try_chain(payload, arr) def try_chain(payload, arr)
arr.reduce(payload) do |r, m| arr.reduce(payload) do |r, m|
if m =~ /^\d+$/ && r.is_a?(Array) # If m is an integer string and r is an array if m =~ /^\d+$/
r[m.to_i] index = m.to_i
r[index] if r.is_a?(Array) || (r.respond_to?(:[]) && index < r.size) # If r is an Array or responds to :[]
else else
r.try(m) || r.try(:[], m) r.try(m) || r.try(:[], m)
end 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