Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

initial work on ruby_version dsl

  • Loading branch information...
commit e97ae7a1e5d7756af919bf144c36b11ba3c16c37 1 parent 464aacb
@hone hone authored
View
5 lib/bundler/cli.rb
@@ -617,6 +617,11 @@ def clean
end
end
+ desc "ruby", "Displays the ruby version specified"
+ def ruby
+ Bundler.ui.info Bundler.definition.ruby_version
+ end
+
private
def setup_cache_all
View
5 lib/bundler/definition.rb
@@ -5,7 +5,7 @@ module Bundler
class Definition
include GemHelpers
- attr_reader :dependencies, :platforms, :sources
+ attr_reader :dependencies, :platforms, :sources, :ruby_version
def self.build(gemfile, lockfile, unlock)
unlock ||= {}
@@ -30,13 +30,14 @@ def self.build(gemfile, lockfile, unlock)
specs, then we can try to resolve locally.
=end
- def initialize(lockfile, dependencies, sources, unlock)
+ def initialize(lockfile, dependencies, sources, unlock, ruby_version = "")
@unlocking = unlock == true || !unlock.empty?
@dependencies, @sources, @unlock = dependencies, sources, unlock
@remote = false
@specs = nil
@lockfile_contents = ""
+ @ruby_version = ruby_version
if lockfile && File.exists?(lockfile)
@lockfile_contents = Bundler.read_file(lockfile)
View
13 lib/bundler/dsl.rb
@@ -25,6 +25,7 @@ def initialize
@groups = []
@platforms = []
@env = nil
+ @ruby_version = ""
end
def eval_gemfile(gemfile)
@@ -144,7 +145,7 @@ def git(uri, options = {}, source_options = {}, &blk)
def to_definition(lockfile, unlock)
@sources << @rubygems_source unless @sources.include?(@rubygems_source)
- Definition.new(lockfile, @dependencies, @sources, unlock)
+ Definition.new(lockfile, @dependencies, @sources, unlock, @ruby_version)
end
def group(*args, &blk)
@@ -169,6 +170,16 @@ def env(name)
@env = old
end
+ def ruby_version(ruby_version, options = {})
+ raise GemfileError, "Please define :engine_version" if options[:engine] && options[:engine_version].nil?
+ raise GemfileError, "Please define :engine" if options[:engine_version] && options[:engine].nil?
+
+ engine = options[:engine] || "ruby"
+ raise GemfileError, "ruby_version must match the :engine_version for MRI" if options[:engine] == "ruby" && options[:engine_version] && ruby_version != options[:engine_version]
+ engine_version = engine == "ruby" ? ruby_version : options[:engine_version]
+ @ruby_version = "ruby #{ruby_version} (#{engine} #{engine_version})"
+ end
+
def method_missing(name, *args)
location = caller[0].split(':')[0..1].join(':')
raise GemfileError, "Undefined local variable or method `#{name}' for Gemfile\n" \
View
94 spec/other/ruby_spec.rb
@@ -0,0 +1,94 @@
+require "spec_helper"
+
+describe "bundle ruby", :focused => true do
+ it "returns ruby version when explicit" do
+ gemfile <<-G
+ source "file://#{gem_repo1}"
+ ruby_version "1.9.3", :engine => 'ruby', :engine_version => '1.9.3'
+
+ gem "foo"
+ G
+
+ bundle "ruby"
+
+ out.should eq("ruby 1.9.3 (ruby 1.9.3)")
+ end
+
+ it "engine defaults to MRI" do
+ gemfile <<-G
+ source "file://#{gem_repo1}"
+ ruby_version "1.9.3"
+
+ gem "foo"
+ G
+
+ bundle "ruby"
+
+ out.should eq("ruby 1.9.3 (ruby 1.9.3)")
+ end
+
+ it "handles jruby" do
+ gemfile <<-G
+ source "file://#{gem_repo1}"
+ ruby_version "1.8.7", :engine => 'jruby', :engine_version => '1.6.5'
+
+ gem "foo"
+ G
+
+ bundle "ruby"
+
+ out.should eq("ruby 1.8.7 (jruby 1.6.5)")
+ end
+
+ it "handles rbx" do
+ gemfile <<-G
+ source "file://#{gem_repo1}"
+ ruby_version "1.8.7", :engine => 'rbx', :engine_version => '1.2.4'
+
+ gem "foo"
+ G
+
+ bundle "ruby"
+
+ out.should eq("ruby 1.8.7 (rbx 1.2.4)")
+ end
+
+ it "raises an error if engine is used but engine version is not" do
+ gemfile <<-G
+ source "file://#{gem_repo1}"
+ ruby_version "1.8.7", :engine => 'rbx'
+
+ gem "foo"
+ G
+
+ bundle "ruby", :exitstatus => true
+
+ exitstatus.should_not == 0
+ end
+
+ it "raises an error if engine_version is used but engine is not" do
+ gemfile <<-G
+ source "file://#{gem_repo1}"
+ ruby_version "1.8.7", :engine_version => '1.2.4'
+
+ gem "foo"
+ G
+
+ bundle "ruby", :exitstatus => true
+
+ exitstatus.should_not == 0
+ end
+
+ it "raises an error if engine version doesn't match ruby version for mri" do
+ gemfile <<-G
+ source "file://#{gem_repo1}"
+ ruby_version "1.8.7", :engine => 'ruby', :engine_version => '1.2.4'
+
+ gem "foo"
+ G
+
+ bundle "ruby", :exitstatus => true
+
+ exitstatus.should_not == 0
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.