summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorNgan Pham <ngan@users.noreply.github.com>2023-08-12 19:16:20 -0700
committergit <svn-admin@ruby-lang.org>2023-08-17 16:07:54 +0000
commit75a4767525407755a33d3b140312c00f2cababd6 (patch)
tree967cd62a92a2d7f1c4b16300ca61bccb80da0ab0 /lib
parent30a5b94517699589f6943163cd6b92f2f6c0023f (diff)
[rubygems/rubygems] Add `file` option to `ruby` method in Gemfile
https://github.com/rubygems/rubygems/commit/fb9354b7bf
Diffstat (limited to 'lib')
-rw-r--r--lib/bundler/man/gemfile.513
-rw-r--r--lib/bundler/man/gemfile.5.ronn5
-rw-r--r--lib/bundler/ruby_dsl.rb6
3 files changed, 24 insertions, 0 deletions
diff --git a/lib/bundler/man/gemfile.5 b/lib/bundler/man/gemfile.5
index f2f9aa6f07..9f6094b853 100644
--- a/lib/bundler/man/gemfile.5
+++ b/lib/bundler/man/gemfile.5
@@ -85,6 +85,19 @@ ruby "3\.1\.2"
.
.IP "" 0
.
+.P
+If you wish to derive your Ruby version from a version file (ie \.ruby\-version), you can use the \fBfile\fR option instead\.
+.
+.IP "" 4
+.
+.nf
+
+ruby file: "\.ruby\-version"
+.
+.fi
+.
+.IP "" 0
+.
.SS "ENGINE"
Each application \fImay\fR specify a Ruby engine\. If an engine is specified, an engine version \fImust\fR also be specified\.
.
diff --git a/lib/bundler/man/gemfile.5.ronn b/lib/bundler/man/gemfile.5.ronn
index 69a26b7685..39cd18d551 100644
--- a/lib/bundler/man/gemfile.5.ronn
+++ b/lib/bundler/man/gemfile.5.ronn
@@ -69,6 +69,11 @@ should be the Ruby version that the engine is compatible with.
ruby "3.1.2"
+If you wish to derive your Ruby version from a version file (ie .ruby-version),
+you can use the `file` option instead.
+
+ ruby file: ".ruby-version"
+
### ENGINE
Each application _may_ specify a Ruby engine. If an engine is specified, an
diff --git a/lib/bundler/ruby_dsl.rb b/lib/bundler/ruby_dsl.rb
index 3b3a0583a5..d054969e8d 100644
--- a/lib/bundler/ruby_dsl.rb
+++ b/lib/bundler/ruby_dsl.rb
@@ -5,9 +5,15 @@ module Bundler
def ruby(*ruby_version)
options = ruby_version.last.is_a?(Hash) ? ruby_version.pop : {}
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[:file]
+ raise GemfileError, "Cannot specify version when using the file option" if ruby_version.any?
+ ruby_version << Bundler.read_file(options[:file]).strip
+ 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"