Class: DescriptionCacheStore Private

Inherits:
CacheStore show all
Defined in:
description_cache_store.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.

DescriptionCacheStore provides methods to fetch and mutate formula descriptions used by the brew desc and brew search commands.

Direct Known Subclasses

CaskDescriptionCacheStore

Constant Summary collapse

Key =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

type_member { { fixed: String } }
Value =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

type_member { { fixed: T.anything } }

Instance Method Summary collapse

Methods inherited from CacheStore

#initialize

Constructor Details

This class inherits a constructor from CacheStore

Instance Method Details

#delete!(formula_name) ⇒ 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.

Delete the formula description from the DescriptionCacheStore.

Parameters:

  • formula_name (String)

    the name of the formula to delete



32
33
34
# File 'description_cache_store.rb', line 32

def delete!(formula_name)
  database.delete(formula_name)
end

#delete_from_formula_names!(formula_names) ⇒ void Also known as: delete_from_cask_tokens!

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.

Use an array of formula names to delete them from the DescriptionCacheStore.

Parameters:

  • formula_names (Array<String>)

    the formulae to delete



91
92
93
94
95
# File 'description_cache_store.rb', line 91

def delete_from_formula_names!(formula_names)
  return if database.empty?

  formula_names.each { delete!(it) }
end

#populate_if_empty!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.

If the database is empty update! it with all known formulae.



40
41
42
43
44
# File 'description_cache_store.rb', line 40

def populate_if_empty!
  return unless database.empty?

  Formula.all.each { |formula| update!(formula.full_name, formula.desc) }
end

#select(&block) ⇒ Hash{Key => Value}

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.

select trusted entries from the underlying database.

Parameters:

  • block (T.proc.params(arg0: Key, arg1: Value).returns(BasicObject))

Returns:



100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'description_cache_store.rb', line 100

def select(&block)
  unless Homebrew::EnvConfig.no_require_tap_trust?
    untrusted_names = []
    database.each_key do |name|
      next unless Utils.full_name?(name)
      next if Homebrew::Trust.trusted?(trust_type, name)

      untrusted_names << name
    end
    delete_from_formula_names!(untrusted_names) if untrusted_names.present?
  end

  database.select(&block)
end

#update!(formula_name, description) ⇒ 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.

Inserts a formula description into the cache if it does not exist or updates the formula description if it does exist.

Parameters:

  • formula_name (String)

    the name of the formula to set

  • description (T.anything)

    the description from the formula to set



23
24
25
# File 'description_cache_store.rb', line 23

def update!(formula_name, description)
  database.set(formula_name, description)
end

#update_from_formula_names!(formula_names) ⇒ 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.

Use an array of formula names to update the DescriptionCacheStore.

Parameters:

  • formula_names (Array<String>)

    the formulae to update



76
77
78
79
80
81
82
83
84
# File 'description_cache_store.rb', line 76

def update_from_formula_names!(formula_names)
  return populate_if_empty! if database.empty?

  formula_names.each do |name|
    update!(name, Formula[name].desc)
  rescue FormulaUnavailableError, Homebrew::UntrustedTapError, *FormulaVersions::IGNORED_EXCEPTIONS
    delete!(name)
  end
end

#update_from_report!(report) ⇒ 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.

Use an update report to update the DescriptionCacheStore.

Parameters:

  • report (ReporterHub)

    an update report generated by cmd/update.rb



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'description_cache_store.rb', line 51

def update_from_report!(report)
  return populate_if_empty! if database.empty?
  return if report.empty?

  renamings = T.cast(report.select_formula_or_cask(:R), T::Array[[String, String]])
  alterations = T.cast(
    report.select_formula_or_cask(:A) +
    report.select_formula_or_cask(:M) +
    renamings.filter_map(&:last),
    T::Array[String],
  )
  deletions = T.cast(
    report.select_formula_or_cask(:D) + renamings.filter_map(&:first),
    T::Array[String],
  )

  update_from_formula_names!(alterations)
  delete_from_formula_names!(deletions)
end