Closed yagudaev closed 4 years ago
Good question, let me try it against master and see if my tests pass :)
Damn you are good @pcreux. I owe you a beer🍺. line_number is accessible within the scope.
Do you think it is worth while passing it more explicitly as a second argument?
Something like
importer = UserImporter.new(path: 'myfile.csv') do
after_build do |user, context|
user.line_number = context.line_number
end
end
line_number
is not really part of the DSL and it almost looks like an unexpected side-effect that we have access to it.
@yagudaev Sorry for the late reply. The block is instance_exec
ed so you have access to the Row
attributes such as line_number
, header
, etc. I believe that it's something that we could document and test.
Passed the line number so it can be consumed by the after_build callback.
In my own code, I'm using this line number to keep a reference to the original csv line that created the record.