Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to customize the DEPENDENCIES_NEXT env: #15

Merged
merged 1 commit into from
Nov 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,16 @@ Dual boot it!
------------
If you want to boot using the dependencies from the `Gemfile_next.lock`, run any bundler command prefixed with the `DEPENDENCIES_NEXT=1` ENV variable. I.e. `DEPENDENCIES_NEXT=1 bundle exec irb`.

Configuration (Optional)
------------------------
By default Bootboot will use the `DEPENDENCIES_NEXT` environment variable to update your Gemfile_next.lock. You can however configure it. For example, if you want the dualboot to happen when the `SHOPIFY_NEXT` env variable is present, you simply have to add this in your Gemfile:

Keep` the Gemfile_next.lock` in sync
```ruby
# Gemfile
Bundler.settings.set_local('booboot_env_previx', 'SHOPIFY')
```

Keep the `Gemfile_next.lock` in sync
------------
When a developer bumps or adds a dependency, Bootboot will ensure that the `Gemfile_next.lock` snapshot gets updated.

Expand Down
18 changes: 16 additions & 2 deletions lib/bootboot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,25 @@ module Bootboot
GEMFILE = Bundler.default_gemfile
GEMFILE_LOCK = Pathname("#{GEMFILE}.lock")
GEMFILE_NEXT_LOCK = Pathname("#{GEMFILE}_next.lock")
DUALBOOT_NEXT = 'DEPENDENCIES_NEXT'
DUALBOOT_PREVIOUS = 'DEPENDENCIES_PREVIOUS'

autoload :GemfileNextAutoSync, 'bootboot/gemfile_next_auto_sync'
autoload :Command, 'bootboot/command'

class << self
def env_next
env_prefix + '_NEXT'
end

def env_previous
env_prefix + '_PREVIOUS'
end

private

def env_prefix
Bundler.settings['bootboot_env_prefix'] || 'DEPENDENCIES'
end
end
end

Bootboot::GemfileNextAutoSync.new.setup
Expand Down
4 changes: 2 additions & 2 deletions lib/bootboot/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ def exec(_cmd, _args)
f.write(<<-EOM)
Plugin.send(:load_plugin, 'bootboot') if Plugin.installed?('bootboot')

if ENV['DEPENDENCIES_NEXT']
if ENV['#{Bootboot.env_next}']
enable_dual_booting if Plugin.installed?('bootboot')

# Add any gem you want here, they will be loaded only when running
# bundler command prefixed with `#{DUALBOOT_NEXT}=1`.
# bundler command prefixed with `#{Bootboot.env_next}=1`.
end
EOM
end
Expand Down
8 changes: 4 additions & 4 deletions lib/bootboot/gemfile_next_auto_sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def opt_in

next if !GEMFILE_NEXT_LOCK.exist? ||
nothing_changed?(current_definition) ||
ENV[DUALBOOT_NEXT] ||
ENV[DUALBOOT_PREVIOUS]
ENV[Bootboot.env_next] ||
ENV[Bootboot.env_previous]

update!(current_definition)
end
Expand Down Expand Up @@ -62,9 +62,9 @@ def update!(current_definition)

def which_env
if Bundler.default_lockfile.to_s =~ /_next\.lock/
DUALBOOT_PREVIOUS
Bootboot.env_previous
else
DUALBOOT_NEXT
Bootboot.env_next
end
end

Expand Down
23 changes: 23 additions & 0 deletions test/bootboot_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,29 @@ def test_sync_the_gemfile_next_after_removal_of_gem
end
end

def test_sync_the_gemfile_next_after_installation_of_new_gem_with_custom_bootboot_env
write_gemfile("source 'https://rubygems.org'\n#{plugin}\n") do |file, _dir|
File.write(file, <<-EOM, mode: 'a')
Bundler.settings.set_local('bootboot_env_prefix', 'SHOPIFY')

if ENV['SHOPIFY_NEXT']
gem 'minitest', '5.11.3'
end
EOM

run_bundler_command('bundle bootboot', file.path)

run_bundler_command('bundle install', file.path, env: { 'SHOPIFY_NEXT' => '1' })
output = run_bundler_command(
'bundle exec ruby -e "require \'minitest\';puts Minitest::VERSION"',
file.path,
env: { 'SHOPIFY_NEXT' => '1' }
)

assert_equal '5.11.3', output.strip
end
end

def test_sync_the_gemfile_next_after_update_of_gem
write_gemfile do |file, _dir|
FileUtils.cp("#{file.path}.lock", gemfile_next(file))
Expand Down