Skip to content

Commit 12144c3

Browse files
authored
Merge pull request #47 from scarver2/bundler-4
Bundler 4 compatibility
2 parents 0b6b5ec + d36f141 commit 12144c3

File tree

5 files changed

+31
-4
lines changed

5 files changed

+31
-4
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ rvm:
77
- 3.0.5
88
- 3.1.3
99
- 3.2.0
10+
- 4.0.0
1011

1112
jobs:
1213
fast_finish: true

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Bundler guard allows to automatically & intelligently install/update bundle when needed.
66

77
* Compatible with Bundler 2.1.x
8-
* Tested against the latest Ruby 2.7.x, 3.0.x, 3.1.x & 3.2.x. See [`.travis-ci.yml`](https://github.com/guard/guard-bundler/blob/master/.travis.yml) for the exact versions.
8+
* Tested against the latest Ruby 2.7.x, 3.0.x, 3.1.x, 3.2.x & 4.0.x. See [`.travis-ci.yml`](https://github.com/guard/guard-bundler/blob/master/.travis.yml) for the exact versions.
99

1010
## Install
1111

guard-bundler.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
1717

1818
s.add_dependency 'guard', '~> 2.2'
1919
s.add_dependency 'guard-compat', '~> 1.1'
20-
s.add_dependency 'bundler', '>= 2.1', '< 3'
20+
s.add_dependency 'bundler', '>= 2.1', '< 5'
2121

2222
s.files = Dir.glob('{lib}/**/*') + %w[LICENSE README.md]
2323
s.require_path = 'lib'

lib/guard/bundler.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# encoding: utf-8
2+
# frozen_string_literal: true
3+
24
require 'bundler'
35

46
require "guard/compat/plugin"
57

68
module Guard
79
class Bundler < Plugin
10+
DEFAULT_LOCKFILE = 'Gemfile.lock'
11+
812
autoload :Notifier, 'guard/bundler/notifier'
913

1014
def start
@@ -33,6 +37,14 @@ def cli?
3337

3438
private
3539

40+
def lockfile_path
41+
if defined?(::Bundler::SharedHelpers) && ::Bundler::SharedHelpers.respond_to?(:default_lockfile)
42+
::Bundler::SharedHelpers.default_lockfile&.to_s || DEFAULT_LOCKFILE
43+
else
44+
DEFAULT_LOCKFILE
45+
end
46+
end
47+
3648
def refresh_bundle
3749
start_at = Time.now
3850
result = bundle_check || bundle_install
@@ -54,12 +66,12 @@ def refresh_bundle
5466
end
5567

5668
def bundle_check
57-
gemfile_lock_mtime = File.exist?('Gemfile.lock') ? File.mtime('Gemfile.lock') : nil
69+
gemfile_lock_mtime = File.exist?(lockfile_path) ? File.mtime(lockfile_path) : nil
5870
::Bundler.with_unbundled_env do
5971
`bundle check`
6072
end
6173
return false unless $? == 0
62-
if gemfile_lock_mtime && gemfile_lock_mtime == File.mtime('Gemfile.lock')
74+
if gemfile_lock_mtime && gemfile_lock_mtime == File.mtime(lockfile_path)
6375
:bundle_already_up_to_date
6476
else
6577
:bundle_installed_using_local_gems

spec/guard/bundler_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,18 @@
123123

124124
end
125125

126+
context '#lockfile_path' do
127+
128+
it 'should return default lockfile path' do
129+
expect(subject.send(:lockfile_path)).to end_with('Gemfile.lock')
130+
end
131+
132+
it 'should return custom lockfile path' do
133+
allow(Bundler::SharedHelpers).to receive(:default_lockfile).and_return('custom.lock')
134+
subject = Guard::Bundler.new
135+
expect(subject.send(:lockfile_path)).to end_with('custom.lock')
136+
end
137+
138+
end
139+
126140
end

0 commit comments

Comments
 (0)