IMDB gem not working on Windows with Ruby 2.2 - Can't use Nokogiri 1.6.7.rc4 - ruby

I am trying to use the IMDB gem on Windows with Ruby 2.2 but this gem seems to force using an older version of Nokogiri which is not compatible with my Ruby's version on Windows.
This is the message I am getting:
The bundle currently has Nokogiri locked at 1.6.2.1.
I do have installed the RC4 version.
Is there any way to force IMDB to use the RC4 version?
Or other solution I did not think about?

Probably the easiest solution on Windows is to create a Virtual Machine with Linux and then install Ruby.
Windows has many problems with properly handling gems.

Preamble and warning
This solution is only an ugly hack and I don't recommend to use it.
The best solution would be a corrected version of imdb-gem with a (possible) “optimistic” version constraint.
Disclaimer 2: I don't use bundler, maybe this solution does not work exactly as I show it. But the process should be similar for bundler.
Source of the problem
The gemspec of the imdb-gem contains the command:
s.add_dependency 'nokogiri', '= 1.6.5'
or in version 0.8.2
s.add_dependency 'nokogiri', '= 1.6.2.1'
If this would contain an optimistic version constraint like
s.add_dependency 'nokogiri', '=~ 1.6'
you could use the version you use (assumed there is no reason for this specific version).
Hacking the gemspec
During gem install the gemspec is copied to a location like
[ruby-installation-path]/lib\ruby\gems\2.1.0\specifications.
Look for the file imdb-0.8.2.gemspec and make this change:
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
# Begin of Hack the nokogiri version
# s.add_runtime_dependency(%q<nokogiri>, ["= 1.6.2.1"])
s.add_runtime_dependency(%q<nokogiri>, ["~> 1.6"])
# End of Hack the nokogiri version
s.add_development_dependency(%q<rake>, ["~> 10.0.3"])
Then try if your script works.
I tested with nokogiri version 1.6.6.2 and detected no problem.
If the version 1.6.7.rc4 works also I would recommend to ask for a change on https://github.com/ariejan/imdb and a new version of the imdb-gem.

Related

Ruby - Digest::Digest is deprecated; Use Digest

I've been getting this warning whenever I run my tests or start rails server.
When I run grep from .rvm folder I see the following:
grep -R 'Digest::Digest' .
./rubies/ruby-2.1.0/lib/ruby/2.1.0/openssl/digest.rb: warn('Digest::Digest is deprecated; Use Digest')
- additional references to openssl and ruby 2.1.0
So it looks like it's a Ruby 2.1.0 bug. Are there any fixes? There are no patches available yet as far as I can tell.
Whilst my app uses Fog and a bunch of other gems that have issues relating to this message, I'm using patched versions that don't have the bug. So I reckon Ruby is at fault here.
Borrowing the reply from this thread
OpenSSL::Digest::Digest has been discouraged to use from very ancient era such as Ruby 1.8 and finally was deprecated recently.
If you search for the error message, you will see that a lot of gems, including fog, were still using the deprecated syntax.
I assume it will take a while before all the gems will be updated. If you came across the deprecation in one of the libs you use, I encourage you to report it to the maintainer.
Here's a few examples
https://github.com/fog/fog/pull/2473
https://github.com/alexreisner/geocoder/pull/580
https://github.com/ruby/ruby/pull/446
It's likely your Rails app depends on a gem that is using that old syntax.
If you're using bundler, a good way to find out what is causing the problem is to grep through all the gems defined in your Gemfile:
# grep (ack or ag) the problem code
bundle show --paths | xargs grep -r Digest::Digest
# here was my output
~/.gem/ruby/2.1.0/gems/fog-1.15.0/lib/fog/cloudstack.rb: ##digest = OpenSSL::Digest::Digest.new('sha1')
~/.gem/ruby/2.1.0/gems/fog-1.15.0/lib/fog/core/hmac.rb: #digest = OpenSSL::Digest::Digest.new('sha1')
~/.gem/ruby/2.1.0/gems/fog-1.15.0/lib/fog/core/hmac.rb: #digest = OpenSSL::Digest::Digest.new('sha256')
# update appropriate gems (in my case fog)
gem install fog
bundle update fog
Also make sure you aren't locked on a gem version in your Gemfile.
# change
gem 'fog', '~> 1.15.0'
# to
gem 'fog', '~> 1.0'
# or omit the version if you are a cowboy/girl
Use OpenSSL::Digest instead of deprecated OpenSSL::Digest::Digest

Ruby 1.9.2 is backward compatible with 1.8.7?

I'm using Ruby 1.9.2 (Yarv).
When I install gems I just use "gem install ".
How can I know which Ruby version they are written in: 1.8.7, 1.9.1 or 1.9.2?
If I'm using the latest version and I install a gem that is written in 1.8.7, then that gem doesn't work?
Eg. Yardstick gem seems to not work with 1.9.2 but perfectly with 1.8.7.
How do you check what version each gem is using?
Could someone enlighten this topic for me.
Unfortunatelly there is no definitive way to check that as there are so many versions and variants or Ruby interpreters (Ruby, JRuby, Iron Ruby) and system platforms. Also one gem which is pure Ruby may not work on all platforms with same interpereter verson, because some OS specific properties could be used.
So you must trust the autor or docs he/she provided. Another way to make sure that your platform is right for gem just run tests enclosed to gem - every well written gem should have such.
There is also small tip: if file contains
# -*- encoding: utf-8 -*-
then autor probably developed the gem with 1.9.x in mind.
There's a website for answering the question: "Is it Ruby 1.9?"
http://isitruby19.com/
It doesn't look like anyone has reported on Yardstick yet:
http://isitruby19.com/yardstick
You could be the first, and report that it's broken in 1.9.

How do I add conditional rubygem requirements to a gem specification?

Is it possible to add a gem dependency only if the person is using a certain version of ruby?
Background: I'm working on a fork of a project that uses Test::Unit::Autorunner and the like. They are part of the standard library in ruby 1.8, but aren't part of the standard library in 1.9.1, and is instead in the "test-unit" gem. I want to add a dependency that says that if someone's using ruby 1.9.1 or later, install the "test-unit" gem, but if they're using 1.8 or earlier, they don't need to install anything.
If you look at the gemspec documentation for add_dependency, there isn't an option for a ruby version. Perhaps you could use the post_install_message attribute to tell the user to install the gem if they're using ruby 1.9.
I did this exact thing for a project. The trick is to add the script as an extension, which will then get executed at install time on the user's machine.
Here are code snippets and links to our github:
First, when in the gemspec (we're actually using a Rakefile to generate it, but the result ends up the same) source
# This file *needs* to be named this, there are other files
# for other extension processors
s.extensions << 'ext/mkrf_conf.rb'
And then the relevant lines in that mkrf_conf.rb source
require 'rubygems/dependency_installer.rb'
inst = Gem::DependencyInstaller.new
inst.install "test-unit" if RUBY_VERSION > "1.9"
Gem doesn't support conditional dependencies (except on gem builder's environment -as noted above), and bundler is not a viable option to solve this either - see https://github.com/carlhuda/bundler/issues/1281
hay ... i'm kind of a ruby newbie ... if this is the best way to do it.
any way ... i wish i can do that using only Ruby .... though u can use your operating system shell to do that, by using this in your program installer, just execute (works for Linux based operating systems):
$ruby --version
(u can execute that from a ruby installer file, just like: ruby --version)
and put a possibility according to output, if it's 1.9.1 add an extra line to execute:
$ sudo gem install gem_name
else, just leave it be.
Checkout this tutorial in the Ruby Programming wikibook.
Tt shows how to install different versions of dependencies depending on what version of ruby the installee is using.
(short answer--it ain't as easy as it should be)
You can't. You need to build two gems, one with
spec.required_ruby_version = '~> 1.8.6'
and one with
spec.required_ruby_version = '~> 1.9.1'
spec.add_dependency 'test-unit', '~> 2.0.5'
Gemspecs are just ruby files anyway, so you can execute any ruby code inside them, so:
spec.add_dependency = 'test-unit', '>= 2.0' if RUBY_VERSION =~ '1.9'
EDIT: Specs run only on the builders machine.

Manually adding a Ruby Gem

I am trying to install the mechanize gem that is supposed to work with 1.9 from here: http://github.com/kemiller/mechanize but I do not know how to add it manually.
I am using Windows, I could just copy the folder to the gems directory, but how do I initialize it?
I'm not sure I understand the problem. gem install mechanize doesn't work? It produces version 0.9.3 for me, which matches the gemspec of the library you linked to.
EDIT: you're on 1.9. I knew that. Disregard my hasty post, not familiar enough with Windows to offer any help on building the extensions.
I would use the bundler gem using the command gem install bundler. This will create a file called Gemfile in your project directory where you can put your dependencies for the specific project that you are working on. In the Gemfile, you will need to specify gem mechanize. If you want a specific version include ~> VERSION after. After, run the command bundle install. This will install the gem you want and use it in your project.

Determining which rubygem you're using

How can you determine which rubygem is being used in response to a "require" statement? gem which doesn't seem to help.
Background: for the project hornsby-herbarium-parser, I'm using the gem roo.
I used the github gem hmcgowan-roo , as at that time it was more recent than the rubyforge version of roo. I tried testing the code on runcoderun, and it failed because it doesn't have any version of roo. By this time, new versions of roo were available on both github and rubyforge.
I decided I may as well see if the latest version from rubyforge works for my code, as I assume rubyforge is more official, authoritative, and stable than github forks. Once I'm sure the rubyforge version works with my code, I'll ask runcoderun nicely if they can install it on their system.
I sudo gem installed roo, and my gems now include "hmcgowan-roo (1.3.5)" and "roo (1.3.6)", and running the tests for hornsby-herbarium-parser still pass. I know that as the rubyforge version was installed more recently, it ought to be the one being used in the tests, but I want to be able to verify this.
gem which roo
Didn't help, because it gave me
(checking gem hmcgowan-roo-1.3.5 for roo)
/usr/lib/ruby/gems/1.8/gems/hmcgowan-roo-1.3.5/lib/roo.rb
which I assume is the wrong answer.
Update: I used both
$:.detect {|dir| dir =~ /roo/}
and
puts Roo::VERSION::STRING
both agree with gem which, saying that I'm still using hmcgowan-roo-1.3.5.
puts Roo::VERSION::STRING
First of all, rubygems will load the highest version number gem, not the most recently installed. So you should be getting roo 1.3.6 here.
Other than that, I second gerrit's suggestion to look for a version constant. For instance, I just loaded rmagick and there is a constant Magick::Version. Another example is Open4::VERSION.
However not all gems have a version constant, so as a fallback you could do something hacky like:
>> require 'open4'
=> true
>> $:.detect {|dir| dir =~ /\/open4-([^\/]*)\//}
=> "/Library/Ruby/Gems/1.8/gems/open4-0.9.6/bin"
>> $1
=> "0.9.6"
gem list xxx
it defaults to load the latest version.
you can do use Gem::VERSION
require 'rubygems'; puts Gem::VERSION
that in a ruby program, which is quite useful if you want to make sure that your application under same version of rubygems accrossing all machines (e.g. bundler Gemfile)
The simplest way will be to uninstall and then reinstall the rubygems individually.
I'm not so sure that your assumption about github not having stable sources is so accurate.

Resources