Class: Descriptions Private
Overview
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
Helper class for printing and searching descriptions.
Class Method Summary collapse
-
.search(string_or_regex, field, cache_store, eval_all = Homebrew::EnvConfig.eval_all?, cache_store_hash: false) ⇒ Object
private
Given a regex, find all formulae whose specified fields contain a match.
Instance Method Summary collapse
-
#initialize(descriptions) ⇒ Descriptions
constructor
private
Create an actual instance.
-
#print ⇒ Object
private
Take search results -- a hash mapping formula names to descriptions -- and print them.
Constructor Details
#initialize(descriptions) ⇒ Descriptions
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Create an actual instance.
29 30 31 |
# File 'descriptions.rb', line 29 def initialize(descriptions) @descriptions = descriptions end |
Class Method Details
.search(string_or_regex, field, cache_store, eval_all = Homebrew::EnvConfig.eval_all?, cache_store_hash: false) ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Given a regex, find all formulae whose specified fields contain a match.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'descriptions.rb', line 11 def self.search(string_or_regex, field, cache_store, eval_all = Homebrew::EnvConfig.eval_all?, cache_store_hash: false) cache_store.populate_if_empty!(eval_all:) unless cache_store_hash results = case field when :name Homebrew::Search.search(cache_store, string_or_regex) { |name, _| name } when :desc Homebrew::Search.search(cache_store, string_or_regex) { |_, desc| desc } when :either Homebrew::Search.search(cache_store, string_or_regex) end new(results) end |
Instance Method Details
#print ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Take search results -- a hash mapping formula names to descriptions -- and print them.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'descriptions.rb', line 35 def print blank = Formatter.warning("[no description]") @descriptions.keys.sort.each do |full_name| short_name = short_names[full_name] printed_name = if short_name_counts[short_name] == 1 short_name else full_name end description = @descriptions[full_name] || blank if description.is_a?(Array) names = description[0] description = description[1] || blank puts "#{Tty.bold}#{printed_name}:#{Tty.reset} (#{names}) #{description}" else puts "#{Tty.bold}#{printed_name}:#{Tty.reset} #{description}" end end end |