Spec-Zone.ru › Homebrew

Class: Descriptions Private

Inherits:
Object
  • Object
  • Descriptions
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

  • .search(string_or_regex, field, cache_store, status_data: {}, eval_all: Homebrew::EnvConfig.tap_trust_configured?) ⇒ T.attached_class private

    Given a regex, find all formulae whose specified fields contain a match.

Instance Method Summary collapse

  • #initialize(descriptions, status_data: {}) ⇒ void constructor private

    Create an actual instance.

  • #print ⇒ void private

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

Constructor Details

#initialize(descriptions, status_data: {}) ⇒ 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:

  • descriptions (Hash{String => String, nil}, Hash{String => Array<String, nil>})
  • status_data (Hash{String => Hash{Symbol => Boolean}}) (defaults to: {})


59
60
61
62
63
64
65
# File 'descriptions.rb', line 59

def initialize(descriptions, status_data: {})
  @descriptions = T.let(
    descriptions,
    T.any(T::Hash[String, T.nilable(String)], T::Hash[String, T::Array[T.nilable(String)]]),
  )
  @status_data = T.let(status_data, T::Hash[String, T::Hash[Symbol, T::Boolean]])
end

Class Method Details

.search(string_or_regex, field, cache_store, status_data: {}, eval_all: Homebrew::EnvConfig.tap_trust_configured?) ⇒ 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:

  • string_or_regex (Regexp, String)
  • field (SearchField)
  • cache_store (DescriptionCacheStore, Hash{String => String, nil}, Hash{String => Array<String, nil>})
  • status_data (Hash{String => Hash{Symbol => Boolean}}) (defaults to: {})
  • eval_all (Boolean) (defaults to: Homebrew::EnvConfig.tap_trust_configured?)

Returns:

  • (T.attached_class)


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'descriptions.rb', line 33

def self.search(string_or_regex, field, cache_store, status_data: {}, eval_all: Homebrew::EnvConfig.tap_trust_configured?)
  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

  results = T.cast(results, T.any(T::Hash[String, T.nilable(String)], T::Hash[String, T::Array[T.nilable(String)]]))

  new(results, status_data: status_data.slice(*results.keys))
end

Instance Method Details

#print ⇒ 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.

This method returns an undefined value.

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



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'descriptions.rb', line 70

def print
  @descriptions.keys.sort.each do |full_name|
    description = @descriptions[full_name]
    next if description.nil?

    short_name = short_names[full_name]
    display_name = if short_name && short_name_counts[short_name] == 1
      short_name
    else
      full_name
    end
    display_name = decorate_name(full_name, display_name, description)
    if description.is_a?(Array)
      names = description[0]
      next if description[1].nil?

      description = T.must(description[1])
      puts names.present? ? "#{display_name}: (#{names}) #{description}" : "#{display_name}: #{description}"
    else
      puts "#{display_name}: #{description}"
    end
  end
end

© 2009–present Homebrew contributors
Licensed under the BSD 2-Clause License.
https://docs.brew.sh/rubydoc/Descriptions.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API