Class: DescriptionCacheStore

Inherits:
CacheStore show all
Includes:
Searchable
Defined in:
brew/Library/Homebrew/description_cache_store.rb

Overview

DescriptionCacheStore provides methods to fetch and mutate linkage-specific data used by the brew linkage command.

Instance Method Summary collapse

Methods included from Searchable

#search

Methods inherited from CacheStore

#initialize

Constructor Details

This class inherits a constructor from CacheStore

Instance Method Details

#delete!(formula_name) ⇒ nil

Delete the formula description from the DescriptionCacheStore.

Parameters:

  • formula_name (String)

    the name of the formula to delete

Returns:

  • (nil)


28
29
30
# File 'brew/Library/Homebrew/description_cache_store.rb', line 28

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

#delete_from_formula_names!(formula_names) ⇒ nil

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

Parameters:

  • formula_names (Array)

    the formulae to delete

Returns:

  • (nil)


78
79
80
81
82
# File 'brew/Library/Homebrew/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!nil

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

Returns:

  • (nil)


34
35
36
37
38
# File 'brew/Library/Homebrew/description_cache_store.rb', line 34

def populate_if_empty!
  return unless database.empty?

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

#update!(formula_name, description) ⇒ nil

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)


20
21
22
# File 'brew/Library/Homebrew/description_cache_store.rb', line 20

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

#update_from_formula_names!(formula_names) ⇒ nil

Use an array of formulae names to update the DescriptionCacheStore.

Parameters:

  • formula_names (Array)

    the formulae to update

Returns:

  • (nil)


62
63
64
65
66
67
68
69
70
71
72
# File 'brew/Library/Homebrew/description_cache_store.rb', line 62

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

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

#update_from_report!(report) ⇒ nil

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
# File 'brew/Library/Homebrew/description_cache_store.rb', line 44

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

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

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