Module: Bundler::CLI::Common
- Defined in:
- lib/bundler/cli/common.rb
Class Method Summary collapse
- .ask_for_spec_from(specs) ⇒ Object
- .clean_after_install? ⇒ Boolean
- .configure_gem_version_promoter(definition, options) ⇒ Object
- .ensure_all_gems_in_lockfile!(names, locked_gems = Bundler.locked_gems) ⇒ Object
- .gem_not_found_message(missing_gem_name, alternatives) ⇒ Object
- .output_fund_metadata_summary ⇒ Object
- .output_post_install_messages(messages) ⇒ Object
- .output_without_groups_message(command) ⇒ Object
- .patch_level_options(options) ⇒ Object
- .print_post_install_message(name, msg) ⇒ Object
- .select_spec(name, regex_match = nil) ⇒ Object
- .without_groups_message(command) ⇒ Object
Class Method Details
.ask_for_spec_from(specs) ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/bundler/cli/common.rb', line 66 def self.ask_for_spec_from(specs) specs.each_with_index do |spec, index| Bundler.ui.info "#{index.succ} : #{spec.name}", true end Bundler.ui.info "0 : - exit -", true num = Bundler.ui.ask("> ").to_i num > 0 ? specs[num - 1] : nil end |
.clean_after_install? ⇒ Boolean
107 108 109 110 111 112 113 |
# File 'lib/bundler/cli/common.rb', line 107 def self.clean_after_install? clean = Bundler.settings[:clean] return clean unless clean.nil? clean ||= Bundler.feature_flag.auto_clean_without_path? && Bundler.settings[:path].nil? clean &&= !Bundler.use_system_gems? clean end |
.configure_gem_version_promoter(definition, options) ⇒ Object
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/bundler/cli/common.rb', line 92 def self.configure_gem_version_promoter(definition, ) patch_level = () patch_level << :patch if patch_level.empty? && Bundler.settings[:prefer_patch] raise InvalidOption, "Provide only one of the following options: #{patch_level.join(", ")}" unless patch_level.length <= 1 definition.gem_version_promoter.tap do |gvp| gvp.level = patch_level.first || :major gvp.strict = [:strict] || ["update-strict"] || ["filter-strict"] end end |
.ensure_all_gems_in_lockfile!(names, locked_gems = Bundler.locked_gems) ⇒ Object
85 86 87 88 89 90 |
# File 'lib/bundler/cli/common.rb', line 85 def self.ensure_all_gems_in_lockfile!(names, locked_gems = Bundler.locked_gems) locked_names = locked_gems.specs.map(&:name).uniq names.-(locked_names).each do |g| raise GemNotFound, (g, locked_names) end end |
.gem_not_found_message(missing_gem_name, alternatives) ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/bundler/cli/common.rb', line 76 def self.(missing_gem_name, alternatives) require_relative "../similarity_detector" = "Could not find gem '#{missing_gem_name}'." alternate_names = alternatives.map {|a| a.respond_to?(:name) ? a.name : a } suggestions = SimilarityDetector.new(alternate_names).similar_word_list(missing_gem_name) += "\nDid you mean #{suggestions}?" if suggestions end |
.output_fund_metadata_summary ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/bundler/cli/common.rb', line 17 def self. definition = Bundler.definition current_dependencies = definition.requested_dependencies current_specs = definition.specs count = current_dependencies.count {|dep| current_specs[dep.name].first..key?("funding_uri") } return if count.zero? intro = count > 1 ? "#{count} installed gems you directly depend on are" : "#{count} installed gem you directly depend on is" = "#{intro} looking for funding.\n Run `bundle fund` for details" Bundler.ui.info end |
.output_post_install_messages(messages) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/bundler/cli/common.rb', line 5 def self.() return if Bundler.settings["ignore_messages"] .to_a.each do |name, msg| (name, msg) unless Bundler.settings["ignore_messages.#{name}"] end end |
.output_without_groups_message(command) ⇒ Object
31 32 33 34 |
# File 'lib/bundler/cli/common.rb', line 31 def self.(command) return if Bundler.settings[:without].empty? Bundler.ui.confirm (command) end |
.patch_level_options(options) ⇒ Object
103 104 105 |
# File 'lib/bundler/cli/common.rb', line 103 def self.() [:major, :minor, :patch].select {|v| .keys.include?(v.to_s) } end |
.print_post_install_message(name, msg) ⇒ Object
12 13 14 15 |
# File 'lib/bundler/cli/common.rb', line 12 def self.(name, msg) Bundler.ui.confirm "Post-install message from #{name}:" Bundler.ui.info msg end |
.select_spec(name, regex_match = nil) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/bundler/cli/common.rb', line 45 def self.select_spec(name, regex_match = nil) specs = [] regexp = Regexp.new(name) if regex_match Bundler.definition.specs.each do |spec| return spec if spec.name == name specs << spec if regexp && spec.name =~ regexp end case specs.count when 0 raise GemNotFound, (name, Bundler.definition.dependencies) when 1 specs.first else ask_for_spec_from(specs) end rescue RegexpError raise GemNotFound, (name, Bundler.definition.dependencies) end |
.without_groups_message(command) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/bundler/cli/common.rb', line 36 def self.(command) command_in_past_tense = command == :install ? "installed" : "updated" groups = Bundler.settings[:without] group_list = [groups[0...-1].join(", "), groups[-1..-1]]. reject {|s| s.to_s.empty? }.join(" and ") group_str = groups.size == 1 ? "group" : "groups" "Gems in the #{group_str} #{group_list} were not #{command_in_past_tense}." end |