Class: Bundler::CLI::Install

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler/cli/install.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Install



6
7
8
# File 'lib/bundler/cli/install.rb', line 6

def initialize(options)
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options



5
6
7
# File 'lib/bundler/cli/install.rb', line 5

def options
  @options
end

Instance Method Details

#runObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/bundler/cli/install.rb', line 10

def run
  Bundler.ui.level = "error" if options[:quiet]

  warn_if_root

  normalize_groups

  Bundler::SharedHelpers.set_env "RB_USER_INSTALL", "1" if Bundler::FREEBSD

  # Disable color in deployment mode
  Bundler.ui.shell = Thor::Shell::Basic.new if options[:deployment]

  check_for_options_conflicts

  check_trust_policy

  if options[:deployment] || options[:frozen] || Bundler.frozen?
    unless Bundler.default_lockfile.exist?
      flag   = "--deployment flag" if options[:deployment]
      flag ||= "--frozen flag"     if options[:frozen]
      flag ||= "deployment setting"
      raise ProductionError, "The #{flag} requires a #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)}. Please make " \
                             "sure you have checked your #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)} into version control " \
                             "before deploying."
    end

    options[:local] = true if Bundler.app_cache.exist?

    if Bundler.feature_flag.deployment_means_frozen?
      Bundler.settings.set_command_option :deployment, true
    else
      Bundler.settings.set_command_option :frozen, true
    end
  end

  # When install is called with --no-deployment, disable deployment mode
  if options[:deployment] == false
    Bundler.settings.set_command_option :frozen, nil
    options[:system] = true
  end

  normalize_settings

  Bundler::Fetcher.disable_endpoint = options["full-index"]

  if options["binstubs"]
    Bundler::SharedHelpers.major_deprecation 2,
      "The --binstubs option will be removed in favor of `bundle binstubs`"
  end

  Plugin.gemfile_install(Bundler.default_gemfile) if Bundler.feature_flag.plugins?

  definition = Bundler.definition
  definition.validate_runtime!

  installer = Installer.install(Bundler.root, definition, options)
  Bundler.load.cache if Bundler.app_cache.exist? && !options["no-cache"] && !Bundler.frozen?

  Bundler.ui.confirm "Bundle complete! #{dependencies_count_for(definition)}, #{gems_installed_for(definition)}."
  Bundler::CLI::Common.output_without_groups_message

  if Bundler.use_system_gems?
    Bundler.ui.confirm "Use `bundle info [gemname]` to see where a bundled gem is installed."
  else
    absolute_path = File.expand_path(Bundler.configured_bundle_path.base_path)
    relative_path = absolute_path.sub(File.expand_path(".") + File::SEPARATOR, "." + File::SEPARATOR)
    Bundler.ui.confirm "Bundled gems are installed into `#{relative_path}`"
  end

  Bundler::CLI::Common.output_post_install_messages installer.post_install_messages

  warn_ambiguous_gems

  if CLI::Common.clean_after_install?
    require "bundler/cli/clean"
    Bundler::CLI::Clean.new(options).run
  end
rescue GemNotFound, VersionConflict => e
  if options[:local] && Bundler.app_cache.exist?
    Bundler.ui.warn "Some gems seem to be missing from your #{Bundler.settings.app_cache_path} directory."
  end

  unless Bundler.definition.has_rubygems_remotes?
    Bundler.ui.warn <<-WARN, :wrap => true
      Your Gemfile has no gem server sources. If you need gems that are \
      not already on your machine, add a line like this to your Gemfile:
      source 'https://rubygems.org'
    WARN
  end
  raise e
rescue Gem::InvalidSpecificationException => e
  Bundler.ui.warn "You have one or more invalid gemspecs that need to be fixed."
  raise e
end