summaryrefslogtreecommitdiff
path: root/lib/bundler/env.rb
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2017-06-12 17:19:25 -0500
committerSamuel Giddins <segiddins@segiddins.me>2017-06-12 17:19:25 -0500
commitb272df089d246f9328768bbe100e3436e4d4bdd3 (patch)
tree741a950ef4e5f41509a3d9eff77648d8edfa7e5d /lib/bundler/env.rb
parent37c888069b68537e5f24802bc3077b5f5fef1b9c (diff)
downloadbundler-b272df089d246f9328768bbe100e3436e4d4bdd3.tar.gz
[Env] Extract table formatting into a methodseg-environment-shebang-mismatch
Diffstat (limited to 'lib/bundler/env.rb')
-rw-r--r--lib/bundler/env.rb22
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/bundler/env.rb b/lib/bundler/env.rb
index ce804f9426..325b96fbfa 100644
--- a/lib/bundler/env.rb
+++ b/lib/bundler/env.rb
@@ -12,13 +12,8 @@ module Bundler
print_gemfile = options.delete(:print_gemfile) { true }
print_gemspecs = options.delete(:print_gemspecs) { true }
- out = String.new("## Environment\n\n```\n")
- env = environment
- environment_ljust = env.map {|(k, _v)| k.to_s.length }.max
- env.each do |(k, v)|
- out << "#{k.to_s.ljust(environment_ljust)} #{v}\n"
- end
- out << "```\n"
+ out = String.new
+ append_formatted_table("Environment", environment, out)
unless Bundler.settings.all.empty?
out << "\n## Bundler settings\n\n```\n"
@@ -108,6 +103,17 @@ module Bundler
out
end
- private_class_method :read_file, :ruby_version, :git_version
+ def self.append_formatted_table(title, pairs, out)
+ return if pairs.empty?
+ out << "\n" unless out.empty?
+ out << "## #{title}\n\n```\n"
+ ljust = pairs.map {|k, _v| k.to_s.length }.max
+ pairs.each do |k, v|
+ out << "#{k.to_s.ljust(ljust)} #{v}\n"
+ end
+ out << "```\n"
+ end
+
+ private_class_method :read_file, :ruby_version, :git_version, :append_formatted_table
end
end