Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Checkin

  • Loading branch information...
commit b27477c8761975683ec35d1a090fbc6cca94f740 0 parents
@kyledrake authored
Showing with 110 additions and 0 deletions.
  1. +1 −0  .gitignore
  2. +32 −0 README.markdown
  3. +54 −0 lib/running.rb
  4. +23 −0 running.gemspec
1  .gitignore
@@ -0,0 +1 @@
+*.gem
32 README.markdown
@@ -0,0 +1,32 @@
+Running
+---
+Helpers for finding out which version of Ruby (MRI 1.8, MRI 1.9, Rubinius, etc) you are using. Use cases include testing with code features only available on certain platforms.
+
+This code was extracted from Bundler, so that it could be used generally by the Ruby community. If you have a missing interpreter you'd like to add, please send a pull request.
+
+Currently the following methods are present:
+
+ Running.ruby?
+ Running.ruby_18?
+ Running.ruby_19?
+
+ # MRI
+ Running.mri?
+ Running.mri_18?
+ Running.mri_19?
+
+ # Rubinius
+ Running.rbx?
+
+ # JRuby
+ Running.jruby?
+
+ # Windows
+ Running.mswin?
+ Running.mingw?
+ Running.mingw_18?
+ Running.mingw_19?
+
+TODO
+---
+- A way to ask which is being run would probably be useful.
54 lib/running.rb
@@ -0,0 +1,54 @@
+require 'rbconfig'
+module Running
+ WINDOWS = RbConfig::CONFIG["host_os"] =~ %r!(msdos|mswin|djgpp|mingw)!
+
+ class << self
+ def ruby?
+ !mswin? && (!defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby" || RUBY_ENGINE == "rbx")
+ end
+
+ def ruby_18?
+ ruby? && RUBY_VERSION < "1.9"
+ end
+
+ def ruby_19?
+ ruby? && RUBY_VERSION >= "1.9"
+ end
+
+ def mri?
+ !mswin? && (!defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby")
+ end
+
+ def mri_18?
+ mri? && RUBY_VERSION < "1.9"
+ end
+
+ def mri_19?
+ mri? && RUBY_VERSION >= "1.9"
+ end
+
+ def rbx?
+ ruby? && !defined?(RUBY_ENGINE).nil? && RUBY_ENGINE == "rbx"
+ end
+
+ def jruby?
+ !defined?(RUBY_ENGINE).nil? && RUBY_ENGINE == "jruby"
+ end
+
+ def mswin?
+ !WINDOWS.nil?
+ end
+
+ def mingw?
+ !WINDOWS.nil? && Gem::Platform.local.os == "mingw32"
+ end
+
+ def mingw_18?
+ mingw? && RUBY_VERSION < "1.9"
+ end
+
+ def mingw_19?
+ mingw? && RUBY_VERSION >= "1.9"
+ end
+ end
+end
23 running.gemspec
@@ -0,0 +1,23 @@
+Gem::Specification.new do |s|
+ s.name = 'running'
+ s.version = '0.0.1'
+ s.authors = ['Kyle Drake']
+ s.email = ['kyledrake@gmail.com']
+ s.homepage = 'http://github.com/kyledrake/running'
+ s.summary = 'Helpers for finding out which version of Ruby (MRI 1.8, MRI 1.9, Rubinius, etc) you are using.'
+ s.description = 'Helpers for finding out which version of Ruby (MRI 1.8, MRI 1.9, Rubinius, etc) you are using. Use cases include testing with code features only available on certain platforms.'
+
+ s.files = `git ls-files`.split("\n")
+ s.require_paths = %w[lib]
+ s.rubyforge_project = s.name
+ s.required_rubygems_version = '>= 1.3.4'
+
+ s.add_dependency 'json'
+ s.add_dependency 'faraday', '>= 0.6.1'
+
+ s.add_development_dependency 'rake', '>= 0'
+ s.add_development_dependency 'wrong', '= 0.5.0'
+ s.add_development_dependency 'minitest', '= 2.2.2'
+ s.add_development_dependency 'webmock', '= 1.6.4'
+ s.add_development_dependency 'hashie', '= 1.0.0'
+end
Please sign in to comment.
Something went wrong with that request. Please try again.