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

Instance Method Summary collapse

Methods inherited from CacheStore

#fetch, #initialize

Constructor Details

This class inherits a constructor from CacheStore

Instance Method Details

#delete!(formula_name) ⇒ nil

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.

Delete the formula description from the DescriptionCacheStore.

Parameters:

  • formula_name (String)

    the name of the formula to delete

Returns:

  • (nil)


26
27
28
# File 'description_cache_store.rb', line 26

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

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

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

Parameters:

  • formula_names (Array)

    the formulae to delete

Returns:

  • (nil)


78
79
80
81
82
# File 'description_cache_store.rb', line 78

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

  formula_names.each(&method(:delete!))
end

#populate_if_empty!(eval_all: Homebrew::EnvConfig.eval_all?) ⇒ nil

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.

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

Returns:

  • (nil)


33
34
35
36
37
38
# File 'description_cache_store.rb', line 33

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) ⇒ 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.

select from the underlying database.



86
87
88
# File 'description_cache_store.rb', line 86

def select(&block)
  database.select(&block)
end

#update!(formula_name, description) ⇒ nil

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.

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 (String)

    the description from the formula to set

Returns:

  • (nil)


18
19
20
# File 'description_cache_store.rb', line 18

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

#update_from_formula_names!(formula_names) ⇒ nil

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.

Use an array of formula names to update the DescriptionCacheStore.

Parameters:

  • formula_names (Array)

    the formulae to update

Returns:

  • (nil)


63
64
65
66
67
68
69
70
71
72
# File 'description_cache_store.rb', line 63

def update_from_formula_names!(formula_names)
  return unless Homebrew::EnvConfig.eval_all?
  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) ⇒ nil

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.

Use an update report to update the DescriptionCacheStore.

Parameters:

  • report (Report)

    an update report generated by cmd/update.rb

Returns:

  • (nil)


44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'description_cache_store.rb', line 44

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

  renamings   = report.select_formula_or_cask(:R)
  alterations = report.select_formula_or_cask(:A) +
                report.select_formula_or_cask(:M) +
                renamings.map(&:last)

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