Skip to content

Commit

Permalink
[rubygems/rubygems] Make RubyDsl a little easier to read; avoid a Has…
Browse files Browse the repository at this point in the history
  • Loading branch information
martinemde authored and matzbot committed Dec 12, 2023
1 parent f466afa commit f671c5d
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions lib/bundler/ruby_dsl.rb
Expand Up @@ -3,22 +3,28 @@
module Bundler
module RubyDsl
def ruby(*ruby_version)
options = ruby_version.last.is_a?(Hash) ? ruby_version.pop : {}
options = ruby_version.pop if ruby_version.last.is_a?(Hash)
ruby_version.flatten!

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?
if options
patchlevel = options[:patchlevel]
engine = options[:engine]
engine_version = options[:engine_version]

if options[:file]
raise GemfileError, "Do not pass version argument when using :file option" unless ruby_version.empty?
ruby_version << normalize_ruby_file(options[:file])
end
raise GemfileError, "Please define :engine_version" if engine && engine_version.nil?
raise GemfileError, "Please define :engine" if engine_version && engine.nil?

if options[:file]
raise GemfileError, "Do not pass version argument when using :file option" unless ruby_version.empty?
ruby_version << normalize_ruby_file(options[:file])
end

if options[:engine] == "ruby" && options[:engine_version] &&
ruby_version != Array(options[:engine_version])
raise GemfileEvalError, "ruby_version must match the :engine_version for MRI"
if engine == "ruby" && engine_version && ruby_version != Array(engine_version)
raise GemfileEvalError, "ruby_version must match the :engine_version for MRI"
end
end
@ruby_version = RubyVersion.new(ruby_version, options[:patchlevel], options[:engine], options[:engine_version])

@ruby_version = RubyVersion.new(ruby_version, patchlevel, engine, engine_version)
end

# Support the various file formats found in .ruby-version files.
Expand Down

0 comments on commit f671c5d

Please sign in to comment.