I have a problem with roo gem. When I upload the file using my Rails app it ends up as a Tempfile on the file system, because I do not want to keep the file but import the spreadsheet data from it.
https://github.com/roo-rb/roo/blob/3ed05e1caef0ce3c5db5c19f1fa14e6f74193079/lib/roo/base.rb#L374
The above line checks if my object responds to seek. And that leads to a problem.
(byebug) filename_or_stream.class
Tempfile
(byebug) filename_or_stream.methods.include? :seek
true
How do you suggest I should go round this problem?
I have tried to suppress the error
https://github.com/bigos/roo/commit/55ec3325ec3131fa34c3e0f5e647160cb17ef114
and was able to continue with my work, but the question still remains, How did the Tempfile get the seek method?
Looking for seek leads to this line
which makes no sense to me and I still do not know why Tempfile responds to seek if the documentation does not say anything about it.
application illustrating the problem
https://github.com/bigos/open_example/blob/master/spec/models/open_sheet_spec.rb
possible simple solution
if file.is_a? Tempfile
@workbook = Roo::OpenOffice.new(file.path)
else
@workbook = Roo::OpenOffice.new(file)
end
But why it was only a problem with Opensheet part of the roo gem? I did not notice the problem in other spreadsheets.