Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 4 additions & 25 deletions Library/Homebrew/cache_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,38 +190,17 @@ def dirty?
# storage mechanism.
#
class CacheStore
extend T::Helpers

abstract!

# @param [CacheStoreDatabase] database
# @return [nil]
sig { params(database: CacheStoreDatabase).void }
def initialize(database)
@database = T.let(database, CacheStoreDatabase)
end

# Inserts new values or updates existing cached values to persistent storage.
#
# @abstract
sig { params(args: T.anything).void }
def update!(*args)
raise NotImplementedError
end

# Fetches cached values in persistent storage according to the type of data
# stored.
#
# @abstract
sig { params(args: T.anything).returns(T.untyped) }
def fetch(*args)
raise NotImplementedError
end

# Deletes data from the cache based on a condition defined in a concrete class.
#
# @abstract
sig { params(args: T.anything).void }
def delete!(*args)
raise NotImplementedError
end

protected

# @return [CacheStoreDatabase]
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/keg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def uninstall(raise_failures: false)
CacheStoreDatabase.use(:linkage) do |db|
break unless db.created?

LinkageCacheStore.new(path, db).delete!
LinkageCacheStore.new(path.to_s, db).delete!
end

FileUtils.rm_r(path)
Expand Down
10 changes: 8 additions & 2 deletions Library/Homebrew/linkage_cache_store.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true # rubocop:todo Sorbet/StrictSigil
# typed: strict
# frozen_string_literal: true

require "cache_store"
Expand All @@ -11,14 +11,16 @@ class LinkageCacheStore < CacheStore
# @param keg_path [String]
# @param database [CacheStoreDatabase]
# @return [nil]
sig { params(keg_path: String, database: CacheStoreDatabase).void }
def initialize(keg_path, database)
@keg_path = keg_path
@keg_path = T.let(keg_path, String)
super(database)
end

# Returns `true` if the database has any value for the current `keg_path`.
#
# @return [Boolean]
sig { returns(T::Boolean) }
def keg_exists?
!database.get(@keg_path).nil?
end
Expand All @@ -28,6 +30,7 @@ def keg_exists?
#
# @param hash_values [Hash] hash containing KVPs of { :type => Hash }
# @return [nil]
sig { params(hash_values: T::Hash[Symbol, T.untyped]).void }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you see if this or any other T.untyped in this file can use T.anything instead?

def update!(hash_values)
hash_values.each_key do |type|
next if HASH_LINKAGE_TYPES.include?(type)
Expand All @@ -43,6 +46,7 @@ def update!(hash_values)
# @param type [Symbol] the type to fetch from the {LinkageCacheStore}
# @raise [TypeError] error if the type is not in `HASH_LINKAGE_TYPES`
# @return [Hash]
sig { params(type: Symbol).returns(T.untyped) }
def fetch(type)
unless HASH_LINKAGE_TYPES.include?(type)
raise TypeError, <<~EOS
Expand All @@ -58,6 +62,7 @@ def fetch(type)
# Delete the keg from the {LinkageCacheStore}.
#
# @return [nil]
sig { void }
def delete!
database.delete(@keg_path)
end
Expand All @@ -69,6 +74,7 @@ def delete!

# @param type [Symbol]
# @return [Hash]
sig { params(type: Symbol).returns(T.untyped) }
def fetch_hash_values(type)
keg_cache = database.get(@keg_path)
return {} unless keg_cache
Expand Down
Loading