Skip to content
This repository has been archived by the owner on Jun 22, 2020. It is now read-only.

Commit

Permalink
Fix curses for supported Ruby versions, including Ruby 1.9.3 .
Browse files Browse the repository at this point in the history
d85ea78 installs curses, because curses has been removed from the
standard library in Ruby 2.1.0 onwards. However, the curses gem does
not appear to work with Ruby 1.9.3 . Thus, it cannot be added as a
dependency in `sidekiq-spy.gemspec`.

`Gemfile` supports the notion of platforms. However, `Gemfile` is not
used at build-time. Add curses as a conditional dependency at install-
time, using `ext/mkrf_conf.rb`, based on

    http://en.wikibooks.org/wiki/Ruby_Programming/RubyGems#How_to_install_different_versions_of_gems_depending_on_which_version_of_ruby_the_installee_is_using

However, the dependency still needs to be satisfied at development-
time. Adding this to `Gemfile` using `:platform => :ruby_21` does not
appear to work in Ruby 1.9.3 , because it is an invalid platform there.
Thus, use `RUBY_VERSION` to specify curses as a development dependency
for Ruby 2.1.0 onwards.

If you know a better way of doing this, I would be very interested to
hear it. :)
  • Loading branch information
tiredpixel committed Jan 5, 2014
1 parent 66a0e21 commit 16ead97
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
27 changes: 27 additions & 0 deletions ext/mkrf_conf.rb
@@ -0,0 +1,27 @@
require 'rubygems/dependency_installer'

# SEE: http://en.wikibooks.org/wiki/Ruby_Programming/RubyGems#How_to_install_different_versions_of_gems_depending_on_which_version_of_ruby_the_installee_is_using

di = Gem::DependencyInstaller.new

begin
if RUBY_VERSION >= '2.1'
puts "Installing curses because Ruby #{RUBY_VERSION}"

# BEWARE: repetition; SEE: sidekiq-spy.gemspec
di.install "curses", "~> 1.0"
else
puts "Not installing curses because Ruby #{RUBY_VERSION}"
end
rescue => e
warn "#{$0}: #{e}"

exit!
end

puts "Writing fake Rakefile"

# Write fake Rakefile for rake since Makefile isn't used
File.open(File.join(File.dirname(__FILE__), 'Rakefile'), 'w') do |f|
f.write("task :default" + $/)
end
16 changes: 15 additions & 1 deletion sidekiq-spy.gemspec
Expand Up @@ -18,10 +18,24 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.extensions += [
'ext/mkrf_conf.rb',
]

spec.add_dependency "sidekiq", "~> 2.15"
spec.add_dependency "curses", "~> 1.0"
# spec.add_dependency "curses", "~> 1.0" # SEE: ext/mkrf_conf.rb

spec.add_development_dependency "bundler", "~> 1.3", "!= 1.5.0"
spec.add_development_dependency "rake"
spec.add_development_dependency "mocha", "~> 0.14"

if RUBY_VERSION >= '2.1'
# This is only for development; note that RUBY_VERSION is evaluated at
# build-time, not install-time. ext/mkrf_conf.rb takes care of the install-
# time dependency; this takes care of the development-time dependency.
# Note that this doesn't work in Gemfile, since :ruby_21 is not a valid
# platform in Ruby 1.9.3 .
# BEWARE: repetition; SEE: ext/mkrf_conf.rb
spec.add_development_dependency "curses", "~> 1.0"
end
end

0 comments on commit 16ead97

Please sign in to comment.