docx icon indicating copy to clipboard operation
docx copied to clipboard

Can't open document using a Pathname. Breaking change between 0.4.0 and 0.6.0

Open hpoo opened this issue 4 years ago • 2 comments

Describe the bug

Upgrading gem from 0.4 to 0.6. Code no longer works since I call Document.open with a Pathname

To Reproduce

see example

example

require 'docx'
pn = Pathname.new("/home/me/mydoc.docx")
doc = Docx::Document.new(pn)

=> undefined method `close' for nil:NilClass

Sample docx file

N/A

Expected behavior

document object could be opened with a Pathname as in version 0.4

Environment

  • Ruby version: (jruby 9.2.14.0 - ruby 2.5.7)
  • docx gem version: [0.6.0
  • OS: Ubuntu

hpoo avatar Apr 23 '21 07:04 hpoo

HI, Docx::Document.new does not support Pathname, expects the path to a docx file given as String.

So the following code would work:

doc = Docx::Document.new("/home/me/mydoc.docx")

if you have any reason why you need to use Pathname instead of String, could you explain it?

satoryu avatar Apr 27 '21 05:04 satoryu

Hi,

Since the major version number of the gem had not changed I thought the API-break was unintentional. Hence the report.

I noticed the issue with some old code using Pathname instead of String. But I can live without Pathname, no problem.

hpoo avatar Apr 27 '21 06:04 hpoo