Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for engine-x.y.z .ruby-version format
Browse files Browse the repository at this point in the history
thedustinmiller committed May 10, 2024
1 parent f13048f commit 6f87755
Showing 3 changed files with 20 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/libyear_bundler/models/ruby.rb
Original file line number Diff line number Diff line change
@@ -182,11 +182,14 @@ def version_from_bundler
::Bundler::RubyVersion.from_string(ruby_version_string).gem_version
end

# TODO: this path should probably be relative to `@lockfile` instead
# TODO: of being relative to the current working directory.
def version_from_ruby_version_file
return unless ::File.exist?('.ruby-version')
::Gem::Version.new(::File.read('.ruby-version').strip)
version_file = File.join(File.dirname(@lockfile), '.ruby-version')
return unless File.exist?(version_file)

version_string = File.read(version_file).strip
version = version_string.split('-', 2).last

::Gem::Version.new(version) if version
end

def version_from_ruby
1 change: 1 addition & 0 deletions spec/fixtures/01/.ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby-2.4.2
12 changes: 12 additions & 0 deletions spec/models/ruby_spec.rb
Original file line number Diff line number Diff line change
@@ -52,6 +52,18 @@ module Models
allow(ruby).to receive(:version_from_ruby).and_return(ruby_version)
expect(ruby.installed_version).to eq(ruby_version)
end

it 'gets the version from .ruby-version file' do
ruby_version = '2.4.2'
lockfile = 'spec/fixtures/01/Gemfile.lock'
release_date_cache = nil
ruby_from_file = described_class.new(lockfile, release_date_cache)
allow(ruby_from_file).to receive(:version_from_bundler).and_return(nil)

ruby = described_class.new(nil, nil)
allow(ruby).to receive(:version_from_bundler).and_return(ruby_version)
expect(ruby_from_file.installed_version.to_s).to eq(ruby.installed_version)
end
end

describe '.installed_version_release_date' do

0 comments on commit 6f87755

Please sign in to comment.