dannnylo/rtesseract

Weird collision between RTesseract and Commander gems

MasterSlowPoke opened this issue · 4 comments

Heya. I've been trying to implement RTesseract in my app and it's been going great in testing so far, thanks for making it! However, once I started running my scripts from the command line, I've started running into a really strange problem when calling RTesseract.new(path):

wrong number of arguments (given 0, expected 1)
/home/libras/.rbenv/versions/2.4.5/lib/ruby/gems/2.4.0/gems/commander-4.4.7/lib/commander/runner.rb:171:in `command'
/home/libras/.rbenv/versions/2.4.5/lib/ruby/gems/2.4.0/gems/commander-4.4.7/lib/commander/delegates.rb:16:in `command'
/home/libras/.rbenv/versions/2.4.5/lib/ruby/gems/2.4.0/gems/rtesseract-3.0.2/lib/rtesseract/command.rb:11:in `initialize'
/home/libras/.rbenv/versions/2.4.5/lib/ruby/gems/2.4.0/gems/rtesseract-3.0.2/lib/rtesseract/text.rb:6:in `new'
/home/libras/.rbenv/versions/2.4.5/lib/ruby/gems/2.4.0/gems/rtesseract-3.0.2/lib/rtesseract/text.rb:6:in `run'
/home/libras/.rbenv/versions/2.4.5/lib/ruby/gems/2.4.0/gems/rtesseract-3.0.2/lib/rtesseract.rb:38:in `to_s'

I've been researching this pretty much all week and I've come to the conclusion that this is some sort of weird collision between the RTesseract and Commander gems. For whatever reason, when RTesseract::Command is initialized, this happens:

From: /home/libras/.rbenv/versions/2.4.5/lib/ruby/gems/2.4.0/gems/rtesseract-3.0.2/lib/rtesseract/command.rb @ line 11 RTesseract::Command#initialize:

     7:     def initialize(source, output, options)
     8:       @source = source
     9:       @output = output
    10:       @options = options
 => 11: binding.pry
    12:       @full_command = [ options.command, @source, @output]
    13:     end

[1] pry(#<RTesseract::Command>)> options.command
ArgumentError: wrong number of arguments (given 0, expected 1)
from /home/libras/.rbenv/versions/2.4.5/lib/ruby/gems/2.4.0/gems/commander-4.4.7/lib/commander/runner.rb:171:in `command'
[2] pry(#<RTesseract::Command>)> options
=> #<RTesseract::Configuration command="tesseract", debug_file="/dev/null">

Even though options is an RTesseract::Configuration object, it's somehow getting a callback or reference of some sort stuck on it from the Commander gem and thinks its a method. I have no idea how to clear this up. Right now I'm going to fork RTesseract and replace options.command with 'tesseract' as that's the only command I need, but I'd rather not have to maintain that long term.

Any ideas?

Hello @MasterSlowPoke ,
Can you test with branch fix_commander_conflict?

Works! Any idea why there was that bleed over?

The commander define the method commad for all objects. How the RTesseract::Configuration is a openstruct all data was called by method missing then commander method was called.

I will generate a new version with this fix, maybe remove the openstruct definition.

This fix is in rtesseract version 3.0.3.
Thanks