summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColby Swandale <colby@taplaboratories.com>2017-04-17 15:05:44 +1000
committerColby Swandale <colby@taplaboratories.com>2017-04-20 22:15:37 +1000
commit052bf9388e677ad30f24a6c7d83b7fa05f3acaf9 (patch)
tree43fb60bb43ccb5c8aceee60a2ae936909d0171ba
parent8eb09da9e71cc2fe7bec5feb3ea484f1a5eab2d6 (diff)
downloadbundler-052bf9388e677ad30f24a6c7d83b7fa05f3acaf9.tar.gz
move implementation of Bundler::Env to class methods
Currently to print the Bundler env report you need to need to invoke it via: Bundler::Env.new.report This change removes the need to instantiate an instance and just call the class method of the same name: Bundler::Env.report
-rw-r--r--lib/bundler/cli.rb2
-rw-r--r--lib/bundler/cli/issue.rb2
-rw-r--r--lib/bundler/env.rb14
-rw-r--r--lib/bundler/friendly_errors.rb2
-rw-r--r--spec/bundler/env_spec.rb15
5 files changed, 17 insertions, 18 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index ba329b78cb..d93f81654b 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -530,7 +530,7 @@ module Bundler
desc "env", "Print information about the environment Bundler is running under"
def env
- Env.new.write($stdout)
+ Env.write($stdout)
end
desc "doctor [OPTIONS]", "Checks the bundle for common problems"
diff --git a/lib/bundler/cli/issue.rb b/lib/bundler/cli/issue.rb
index ace0f985a9..91f827ea99 100644
--- a/lib/bundler/cli/issue.rb
+++ b/lib/bundler/cli/issue.rb
@@ -26,7 +26,7 @@ module Bundler
EOS
- Bundler.ui.info Bundler::Env.new.report
+ Bundler.ui.info Bundler::Env.report
Bundler.ui.info "\n## Bundle Doctor"
doctor
diff --git a/lib/bundler/env.rb b/lib/bundler/env.rb
index 284cc2ff30..3790210351 100644
--- a/lib/bundler/env.rb
+++ b/lib/bundler/env.rb
@@ -4,11 +4,11 @@ require "bundler/source/git/git_proxy"
module Bundler
class Env
- def write(io)
+ def self.write(io)
io.write report
end
- def report(options = {})
+ def self.report(options = {})
print_gemfile = options.delete(:print_gemfile) { true }
print_gemspecs = options.delete(:print_gemspecs) { true }
@@ -61,9 +61,7 @@ module Bundler
out
end
- private
-
- def read_file(filename)
+ def self.read_file(filename)
File.read(filename.to_s).strip
rescue Errno::ENOENT
"<No #{filename} found>"
@@ -71,7 +69,7 @@ module Bundler
"#{e.class}: #{e.message}"
end
- def ruby_version
+ def self.ruby_version
str = String.new("#{RUBY_VERSION}")
if RUBY_VERSION < "1.9"
str << " (#{RUBY_RELEASE_DATE}"
@@ -83,10 +81,12 @@ module Bundler
end
end
- def git_version
+ def self.git_version
Bundler::Source::Git::GitProxy.new(nil, nil, nil).full_version
rescue Bundler::Source::Git::GitNotInstalledError
"not installed"
end
+
+ private_class_method :read_file, :ruby_version, :git_version
end
end
diff --git a/lib/bundler/friendly_errors.rb b/lib/bundler/friendly_errors.rb
index 3ba3dcdd91..9caeeee1a5 100644
--- a/lib/bundler/friendly_errors.rb
+++ b/lib/bundler/friendly_errors.rb
@@ -92,7 +92,7 @@ module Bundler
#{e.backtrace && e.backtrace.join("\n ").chomp}
```
- #{Bundler::Env.new.report}
+ #{Bundler::Env.report}
--- TEMPLATE END ----------------------------------------------------------------
EOS
diff --git a/spec/bundler/env_spec.rb b/spec/bundler/env_spec.rb
index 269c323ac6..a2afe5dc52 100644
--- a/spec/bundler/env_spec.rb
+++ b/spec/bundler/env_spec.rb
@@ -3,18 +3,17 @@ require "spec_helper"
require "bundler/settings"
RSpec.describe Bundler::Env do
- let(:env) { described_class.new }
let(:git_proxy_stub) { Bundler::Source::Git::GitProxy.new(nil, nil, nil) }
describe "#report" do
it "prints the environment" do
- out = env.report
+ out = described_class.report
expect(out).to include("Environment")
expect(out).to include(Bundler::VERSION)
expect(out).to include(Gem::VERSION)
- expect(out).to include(env.send(:ruby_version))
- expect(out).to include(env.send(:git_version))
+ expect(out).to include(described_class.send(:ruby_version))
+ expect(out).to include(described_class.send(:git_version))
expect(out).to include(OpenSSL::OPENSSL_VERSION)
end
@@ -36,7 +35,7 @@ RSpec.describe Bundler::Env do
L
end
- let(:output) { env.report(:print_gemfile => true) }
+ let(:output) { described_class.report(:print_gemfile => true) }
it "prints the Gemfile" do
expect(output).to include("Gemfile")
@@ -50,7 +49,7 @@ RSpec.describe Bundler::Env do
end
context "when there no Gemfile and print_gemfile is true" do
- let(:output) { env.report(:print_gemfile => true) }
+ let(:output) { described_class.report(:print_gemfile => true) }
it "prints the environment" do
expect(output).to start_with("## Environment")
@@ -76,7 +75,7 @@ RSpec.describe Bundler::Env do
end
it "prints the gemspec" do
- output = env.report(:print_gemspecs => true)
+ output = described_class.report(:print_gemspecs => true)
expect(output).to include("foo.gemspec")
expect(output).to include(gemspec)
@@ -89,7 +88,7 @@ RSpec.describe Bundler::Env do
and_return("git version 1.2.3 (Apple Git-BS)")
expect(Bundler::Source::Git::GitProxy).to receive(:new).and_return(git_proxy_stub)
- expect(env.report).to include("Git 1.2.3 (Apple Git-BS)")
+ expect(described_class.report).to include("Git 1.2.3 (Apple Git-BS)")
end
end
end