diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2016-01-27 14:01:11 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2016-01-27 14:01:11 -0800 |
commit | ce84bf9ef456b965c4af9c052fc828e089e6cde1 (patch) | |
tree | bef1b3af49111badc9fb9f8cf145e3fc1ac4ef93 | |
parent | 033fc4eda64916b02956fafa627faf68f2aa3a37 (diff) | |
download | bundler-ce84bf9ef456b965c4af9c052fc828e089e6cde1.tar.gz |
Allow passing UI object into bundler/inline
Added an argument to the gemfile method to allow overriding the
UI object. Useful to override the default output format and
send those log events to a logfile or decorate them (timestamps,
severity, etc) before emitting them.
-rw-r--r-- | lib/bundler/inline.rb | 4 | ||||
-rw-r--r-- | spec/runtime/inline_spec.rb | 18 |
2 files changed, 20 insertions, 2 deletions
diff --git a/lib/bundler/inline.rb b/lib/bundler/inline.rb index 9df19b02ad..4de025a5a4 100644 --- a/lib/bundler/inline.rb +++ b/lib/bundler/inline.rb @@ -27,7 +27,7 @@ # # puts Pod::VERSION # => "0.34.4" # -def gemfile(install = false, &gemfile) +def gemfile(install = false, ui = nil, &gemfile) require "bundler" old_root = Bundler.method(:root) def Bundler.root @@ -43,7 +43,7 @@ def gemfile(install = false, &gemfile) definition.validate_ruby! if install - Bundler.ui = Bundler::UI::Shell.new + Bundler.ui = ui || Bundler::UI::Shell.new Bundler::Installer.install(Bundler.root, definition, :system => true) Bundler::Installer.post_install_messages.each do |name, message| Bundler.ui.info "Post-install message from #{name}:\n#{message}" diff --git a/spec/runtime/inline_spec.rb b/spec/runtime/inline_spec.rb index a5142d34ed..8356e37536 100644 --- a/spec/runtime/inline_spec.rb +++ b/spec/runtime/inline_spec.rb @@ -93,4 +93,22 @@ describe "bundler/inline#gemfile" do expect(err).to eq("") expect(exitstatus).to be_zero if exitstatus end + + it "lets me use my own ui object" do + script <<-RUBY, :artifice => "endpoint" + require 'bundler' + class MyBundlerUI < Bundler::UI::Silent + def confirm(msg, newline = nil) + puts "CONFIRMED!" + end + end + gemfile(true, MyBundlerUI.new) do + source "https://rubygems.org" + gem "activesupport", :require => true + end + RUBY + + expect(out).to eq("CONFIRMED!") + expect(exitstatus).to be_zero if exitstatus + end end |