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



30
31
32
# File 'description_cache_store.rb', line 30

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



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

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

  formula_names.each { delete!(it) }
end

#populate_if_empty!(eval_all: Homebrew::EnvConfig.eval_all?) ⇒ 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.

Parameters:

  • eval_all (Boolean) (defaults to: Homebrew::EnvConfig.eval_all?)


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

def populate_if_empty!(eval_all: Homebrew::EnvConfig.eval_all?)
  return unless eval_all
  return unless database.empty?

  Formula.all(eval_all:).each { |f| update!(f.full_name, f.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 from the underlying database.

Parameters:

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

Returns:



101
102
103
# File 'description_cache_store.rb', line 101

def select(&block)
  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



21
22
23
# File 'description_cache_store.rb', line 21

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



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

def update_from_formula_names!(formula_names)
  unless Homebrew::EnvConfig.eval_all?
    database.clear!
    return
  end
  return populate_if_empty! if database.empty?

  formula_names.each do |name|
    update!(name, Formula[name].desc)
  rescue FormulaUnavailableError, *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



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

def update_from_report!(report)
  unless Homebrew::EnvConfig.eval_all?
    database.clear!
    return
  end
  return populate_if_empty! if database.empty?
  return if report.empty?

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

  update_from_formula_names!(alterations)
  delete_from_formula_names!(report.select_formula_or_cask(:D) +
                             renamings.filter_map(&:first))
end