Browse files

delay rubygems/security so we can catch LoadErrors

  • Loading branch information...
1 parent 617bed3 commit dc6f8b3e08ac17d4189e23d71764de679f3dc98e @indirect indirect committed Mar 2, 2013
Showing with 18 additions and 8 deletions.
  1. +7 −6 lib/bundler/cli.rb
  2. +11 −2 lib/bundler/rubygems_integration.rb
View
13 lib/bundler/cli.rb
@@ -1,7 +1,6 @@
+require 'bundler'
require 'bundler/similarity_detector'
require 'bundler/vendored_thor'
-require 'rubygems/user_interaction'
-require 'rubygems/security'
module Bundler
class CLI < Thor
@@ -170,8 +169,10 @@ def check
"Use the rubygems modern index instead of the API endpoint"
method_option "clean", :type => :boolean, :banner =>
"Run bundle clean automatically after install"
- method_option "trust-policy", :alias => "P", :type => :string, :banner =>
- "Gem trust policy (like gem install -P). Must be one of " + Gem::Security::Policies.keys.join('|')
+ unless Bundler.rubygems.security_policies.empty?
+ method_option "trust-policy", :alias => "P", :type => :string, :banner =>
+ "Gem trust policy (like gem install -P). Must be one of " + Bundler.rubygems.security_policies.keys.join('|')
+ end
def install
opts = options.dup
@@ -193,9 +194,9 @@ def install
end
if (opts["trust-policy"])
- unless (Gem::Security::Policies.keys.include?(opts["trust-policy"]))
+ unless (Bundler.rubygems.security_policies.keys.include?(opts["trust-policy"]))
Bundler.ui.error "Rubygems doesn't know about trust policy '#{opts["trust-policy"]}'. " \
- "The known policies are: #{Gem::Security::Policies.keys.join(', ')}."
+ "The known policies are: #{Bundler.rubygems.security_policies.keys.join(', ')}."
exit 1
end
Bundler.settings["trust-policy"] = opts["trust-policy"]
View
13 lib/bundler/rubygems_integration.rb
@@ -166,6 +166,15 @@ def download_gem(spec, uri, path)
Gem::RemoteFetcher.fetcher.download(spec, uri, path)
end
+ def security_policies
+ @security_policies ||= begin
+ require 'rubygems/security'
+ Gem::Security::Policies
+ rescue LoadError
+ {}
+ end
+ end
+
def reverse_rubygems_kernel_mixin
# Disable rubygems' gem activation system
::Kernel.class_eval do
@@ -424,8 +433,6 @@ def preserve_paths
# Rubygems 2.0
class Future < RubygemsIntegration
- require 'rubygems/package'
-
def stub_rubygems(specs)
Gem::Specification.all = specs
@@ -460,12 +467,14 @@ def fetch_all_remote_specs
end
def gem_from_path(path, policy = nil)
+ require 'rubygems/package'
p = Gem::Package.new(path)
p.security_policy = policy if policy
return p
end
def build(spec)
+ require 'rubygems/package'
Gem::Package.build(spec)
end

0 comments on commit dc6f8b3

Please sign in to comment.