Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
initial work on ruby_version dsl
Browse files Browse the repository at this point in the history
  • Loading branch information
hone committed May 3, 2012
1 parent 464aacb commit e97ae7a
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 3 deletions.
5 changes: 5 additions & 0 deletions lib/bundler/cli.rb
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions lib/bundler/definition.rb
Expand Up @@ -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 ||= {}
Expand All @@ -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)
Expand Down
13 changes: 12 additions & 1 deletion lib/bundler/dsl.rb
Expand Up @@ -25,6 +25,7 @@ def initialize
@groups = []
@platforms = []
@env = nil
@ruby_version = ""
end

def eval_gemfile(gemfile)
Expand Down Expand Up @@ -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)
Expand All @@ -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" \
Expand Down
94 changes: 94 additions & 0 deletions 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

0 comments on commit e97ae7a

Please sign in to comment.