diff --git a/Library/Homebrew/cache_store.rb b/Library/Homebrew/cache_store.rb index d9c2440f7043b..0393b5aeb73ac 100644 --- a/Library/Homebrew/cache_store.rb +++ b/Library/Homebrew/cache_store.rb @@ -190,6 +190,10 @@ def dirty? # storage mechanism. # class CacheStore + extend T::Helpers + + abstract! + # @param [CacheStoreDatabase] database # @return [nil] sig { params(database: CacheStoreDatabase).void } @@ -197,31 +201,6 @@ 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] diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb index c975c36b27cce..4cf8e14b6f872 100644 --- a/Library/Homebrew/keg.rb +++ b/Library/Homebrew/keg.rb @@ -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) diff --git a/Library/Homebrew/linkage_cache_store.rb b/Library/Homebrew/linkage_cache_store.rb index 18d607b31e6fb..00ccc6ef78426 100644 --- a/Library/Homebrew/linkage_cache_store.rb +++ b/Library/Homebrew/linkage_cache_store.rb @@ -1,4 +1,4 @@ -# typed: true # rubocop:todo Sorbet/StrictSigil +# typed: strict # frozen_string_literal: true require "cache_store" @@ -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 @@ -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 } def update!(hash_values) hash_values.each_key do |type| next if HASH_LINKAGE_TYPES.include?(type) @@ -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 @@ -58,6 +62,7 @@ def fetch(type) # Delete the keg from the {LinkageCacheStore}. # # @return [nil] + sig { void } def delete! database.delete(@keg_path) end @@ -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