applicationsonline / librarian

Librarian - A Framework for Bundlers. Librarian-Chef is at: https://github.com/applicationsonline/librarian-chef.
http://applicationsonline.com/
MIT License
655 stars 71 forks source link

undefined method `binread' #141

Closed Dextro closed 11 years ago

Dextro commented 11 years ago

$ librarian-chef install /Library/Ruby/Gems/1.8/gems/librarian-0.0.26/lib/librarian/chef/manifest_reader.rb:49:in binread': undefined methodbinread' for #Pathname:0x10ec38b60 (NoMethodError)

Dextro commented 11 years ago

fixed. Apparently my Ruby version was too old.

yfeldblum commented 11 years ago

In the 1.8 series, only 1.8.7+ is supported. What version did you have?

Dextro commented 11 years ago

I got the error with the default in Mountain Lion: ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]

nilbus commented 11 years ago

I ran into this issue today too. Pathname#binread was introduced in ruby 1.9 and is not available in 1.8.7, so this is a 1.8.7 compatibility issue with librarian.

nilbus commented 11 years ago

librarian-0.0.26/lib/librarian/chef/manifest_reader.rb @ line 49:

if IO.respond_to?(:binread)
  def binread(path)
    path.binread
  end
else
  def binread(path)
    path.read
  end
end

The issue is that thor is monkey-patching IO to define binread but does not define Pathname#binread.

/Library/Ruby/Gems/1.8/gems/thor-0.18.1/lib/thor/core_ext/io_binary_read.rb @ line 4:

def binread(file, *args)
  raise ArgumentError, "wrong number of arguments (#{1 + args.size} for 1..3)" unless args.size < 3
  File.open(file, 'rb') do |f|
    f.read(*args)
  end
end unless method_defined? :binread

Librarian can deal with it by instead checking:

if Pathname.method_defined? :binread

I don't know how or if this applies to the master branch, since lib/librarian/chef/manifest_reader.rb no longer exists.

nilbus commented 11 years ago

This issue started sometime after thor-0.17.0 and before or at 0.18.1.

yfeldblum commented 11 years ago

Thanks for reminding me why I'm not a fan of monkey-patches in libraries.

yfeldblum commented 11 years ago

This should be fixed in librarian-chef master here: https://github.com/applicationsonline/librarian-chef/commit/76cb3cbee990fced59836578bb07d2dd9411133d

yfeldblum commented 11 years ago

Anyone want to check if this is fixed in librarian-chef v0.0.1?