Class: Descriptions Private

Inherits:
Object show all
Defined in:
descriptions.rb

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.

Defined Under Namespace

Classes: SearchField

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(descriptions) ⇒ void

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.

Parameters:



50
51
52
# File 'descriptions.rb', line 50

def initialize(descriptions)
  @descriptions = T.let(descriptions, T.any(T::Hash[String, String], T::Hash[String, T::Array[String]]))
end

Class Method Details

.search(string_or_regex, field, cache_store, eval_all = Homebrew::EnvConfig.eval_all?) ⇒ T.attached_class

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.

Parameters:

Returns:

  • (T.attached_class)


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'descriptions.rb', line 31

def self.search(string_or_regex, field, cache_store, eval_all = Homebrew::EnvConfig.eval_all?)
  cache_store.populate_if_empty!(eval_all:) if cache_store.is_a?(DescriptionCacheStore)

  results = case field
  when SearchField::Name
    Homebrew::Search.search(cache_store, string_or_regex) { |name, _| name }
  when SearchField::Description
    Homebrew::Search.search(cache_store, string_or_regex) { |_, desc| desc }
  when SearchField::Either
    Homebrew::Search.search(cache_store, string_or_regex)
  else
    T.absurd(field)
  end

  new(T.cast(results, T.any(T::Hash[String, String], T::Hash[String, T::Array[String]])))
end

Instance Method Details

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.

This method returns an undefined value.

Take search results -- a hash mapping formula names to descriptions -- and print them.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'descriptions.rb', line 57

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 && 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