Class: CaskDescriptionCacheStore

Inherits:
DescriptionCacheStore show all
Defined in:
description_cache_store.rb

Overview

CaskDescriptionCacheStore provides methods to fetch and mutate cask descriptions used by the brew desc and brew search commands.

Instance Method Summary collapse

Methods inherited from DescriptionCacheStore

#delete!, #delete_from_formula_names!, #update!, #update_from_formula_names!

Methods included from Searchable

#search

Methods inherited from CacheStore

#delete!, #fetch, #initialize, #update!

Constructor Details

This class inherits a constructor from CacheStore

Instance Method Details

#populate_if_empty!nil

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

Returns:

  • (nil)


102
103
104
105
106
107
# File 'description_cache_store.rb', line 102

def populate_if_empty!
  return unless database.empty?

  # TODO: 3.6.0: consider if we want to actually read all contents of all casks or odeprecate.
  Cask::Cask.all.each { |c| update!(c.full_name, [c.name.join(", "), c.desc.presence]) }
end

#update_from_cask_tokens!(cask_tokens) ⇒ nil

Use an array of cask tokens to update the CaskDescriptionCacheStore.

Parameters:

  • cask_tokens (Array)

    the casks to update

Returns:

  • (nil)


128
129
130
131
132
133
134
135
136
137
# File 'description_cache_store.rb', line 128

def update_from_cask_tokens!(cask_tokens)
  return populate_if_empty! if database.empty?

  cask_tokens.each do |token|
    c = Cask::CaskLoader.load(token)
    update!(c.full_name, [c.name.join(", "), c.desc.presence])
  rescue Cask::CaskUnavailableError, *FormulaVersions::IGNORED_EXCEPTIONS
    delete!(c.full_name) if c.present?
  end
end

#update_from_report!(report) ⇒ nil

Use an update report to update the CaskDescriptionCacheStore.

Parameters:

  • report (Report)

    an update report generated by cmd/update.rb

Returns:

  • (nil)


113
114
115
116
117
118
119
120
121
122
# File 'description_cache_store.rb', line 113

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

  alterations = report.select_formula(:AC) +
                report.select_formula(:MC)

  update_from_cask_tokens!(alterations)
  delete_from_cask_tokens!(report.select_formula(:DC))
end