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

Commit

Permalink
refactor ruby version into it's own class
Browse files Browse the repository at this point in the history
  • Loading branch information
hone committed May 3, 2012
1 parent e97ae7a commit 384c72c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/bundler.rb
Expand Up @@ -27,6 +27,7 @@ module Bundler
autoload :MatchPlatform, 'bundler/match_platform'
autoload :RemoteSpecification, 'bundler/remote_specification'
autoload :Resolver, 'bundler/resolver'
autoload :RubyVersion, 'bundler/ruby_version'
autoload :Runtime, 'bundler/runtime'
autoload :Settings, 'bundler/settings'
autoload :SharedHelpers, 'bundler/shared_helpers'
Expand Down
4 changes: 1 addition & 3 deletions lib/bundler/dsl.rb
Expand Up @@ -174,10 +174,8 @@ 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})"
@ruby_version = RubyVersion.new(ruby_version, options[:engine], options[:engine_version])
end

def method_missing(name, *args)
Expand Down
15 changes: 15 additions & 0 deletions lib/bundler/ruby_version.rb
@@ -0,0 +1,15 @@
module Bundler
class RubyVersion
attr_reader :version, :engine, :engine_version

def initialize(version, engine, engine_version)
@version = version
@engine = engine || "ruby"
@engine_version = @engine == "ruby" ? version : engine_version
end

def to_s
"ruby #{@version} (#{@engine} #{@engine_version})"
end
end
end

0 comments on commit 384c72c

Please sign in to comment.