88# residing in the `HOMEBREW_CACHE`.
99#
1010class CacheStoreDatabase
11- extend T ::Generic
12-
13- # Sorbet type members are mutable by design and cannot be frozen.
14- Key = type_member # rubocop:disable Style/MutableConstant
15- # Sorbet type members are mutable by design and cannot be frozen.
16- Value = type_member # rubocop:disable Style/MutableConstant
17-
1811 # Yields the cache store database.
1912 # Closes the database after use if it has been loaded.
13+ #
14+ # @param [Symbol] type
15+ # @yield [CacheStoreDatabase] self
2016 sig {
2117 type_parameters ( :U )
2218 . params (
2319 type : Symbol ,
24- _blk : T . proc . params ( arg0 : CacheStoreDatabase [ T . anything , T . anything ] ) . returns ( T . type_parameter ( :U ) ) ,
20+ _blk : T . proc . params ( arg0 : CacheStoreDatabase ) . returns ( T . type_parameter ( :U ) ) ,
2521 )
2622 . returns ( T . type_parameter ( :U ) )
2723 }
@@ -51,29 +47,32 @@ def self.use(type, &_blk)
5147 end
5248
5349 # Creates a CacheStoreDatabase.
50+ #
51+ # @param [Symbol] type
52+ # @return [nil]
5453 sig { params ( type : Symbol ) . void }
5554 def initialize ( type )
5655 @type = type
5756 @dirty = T . let ( false , T . nilable ( T ::Boolean ) )
5857 end
5958
6059 # Sets a value in the underlying database (and creates it if necessary).
61- sig { params ( key : Key , value : Value ) . void }
60+ sig { params ( key : T . anything , value : T . anything ) . void }
6261 def set ( key , value )
6362 dirty!
6463 db [ key ] = value
6564 end
6665
6766 # Gets a value from the underlying database (if it already exists).
68- sig { params ( key : Key ) . returns ( T . nilable ( Value ) ) }
67+ sig { params ( key : T . anything ) . returns ( T . untyped ) }
6968 def get ( key )
7069 return unless created?
7170
7271 db [ key ]
7372 end
7473
7574 # Deletes a value from the underlying database (if it already exists).
76- sig { params ( key : Key ) . void }
75+ sig { params ( key : T . anything ) . void }
7776 def delete ( key )
7877 return unless created?
7978
@@ -100,12 +99,16 @@ def write_if_dirty!
10099 end
101100
102101 # Returns `true` if the cache file has been created for the given `@type`.
102+ #
103+ # @return [Boolean]
103104 sig { returns ( T ::Boolean ) }
104105 def created?
105106 cache_path . exist?
106107 end
107108
108109 # Returns the modification time of the cache file (if it already exists).
110+ #
111+ # @return [Time]
109112 sig { returns ( T . nilable ( Time ) ) }
110113 def mtime
111114 return unless created?
@@ -114,23 +117,25 @@ def mtime
114117 end
115118
116119 # Performs a `select` on the underlying database.
117- sig {
118- overridable . params ( block : T . proc . params ( arg0 : Key , arg1 : Value ) . returns ( BasicObject ) ) . returns ( T :: Hash [ Key , Value ] )
119- }
120+ #
121+ # @return [Hash]
122+ sig { params ( block : T . proc . params ( arg0 : T . untyped , arg1 : T . untyped ) . returns ( BasicObject ) ) . returns ( T :: Hash [ T . untyped , T . untyped ] ) }
120123 def select ( &block )
121124 db . select ( &block )
122125 end
123126
124127 # Returns `true` if the cache is empty.
128+ #
129+ # @return [Boolean]
125130 sig { returns ( T ::Boolean ) }
126131 def empty?
127132 db . empty?
128133 end
129134
130135 # Performs a `each_key` on the underlying database.
131- sig {
132- params ( block : T . proc . params ( arg0 : Key ) . returns ( BasicObject ) ) . returns ( T :: Hash [ Key , Value ] )
133- }
136+ #
137+ # @return [Hash]
138+ sig { params ( block : T . proc . params ( arg0 : T . untyped ) . returns ( BasicObject ) ) . returns ( T :: Hash [ T . untyped , T . untyped ] ) }
134139 def each_key ( &block )
135140 db . each_key ( &block )
136141 end
@@ -140,9 +145,11 @@ def each_key(&block)
140145 # Lazily loaded database in read/write mode. If this method is called, a
141146 # database file will be created in the `HOMEBREW_CACHE` with a name
142147 # corresponding to the `@type` instance variable.
143- sig { returns ( T ::Hash [ Key , Value ] ) }
148+ #
149+ # @return [Hash] db
150+ sig { returns ( T ::Hash [ T . untyped , T . untyped ] ) }
144151 def db
145- @db ||= T . let ( { } , T . nilable ( T ::Hash [ Key , Value ] ) )
152+ @db ||= T . let ( { } , T . nilable ( T ::Hash [ T . untyped , T . untyped ] ) )
146153 return @db if !@db . empty? || !created?
147154
148155 begin
@@ -156,6 +163,8 @@ def db
156163
157164 # The path where the database resides in the `HOMEBREW_CACHE` for the given
158165 # `@type`.
166+ #
167+ # @return [Pathname]
159168 sig { returns ( Pathname ) }
160169 def cache_path
161170 HOMEBREW_CACHE /"#{ @type } .json"
@@ -168,6 +177,8 @@ def dirty!
168177 end
169178
170179 # Returns `true` if the cache needs to be written to disk.
180+ #
181+ # @return [Boolean]
171182 sig { returns ( T ::Boolean ) }
172183 def dirty?
173184 !!@dirty
@@ -179,23 +190,20 @@ def dirty?
179190# storage mechanism.
180191#
181192class CacheStore # rubocop:todo Style/OneClassPerFile
182- extend T ::Generic
183193 extend T ::Helpers
184194
185195 abstract!
186196
187- # Sorbet type members are mutable by design and cannot be frozen.
188- Key = type_member # rubocop:disable Style/MutableConstant
189- # Sorbet type members are mutable by design and cannot be frozen.
190- Value = type_member # rubocop:disable Style/MutableConstant
191-
192- sig { params ( database : CacheStoreDatabase [ Key , Value ] ) . void }
197+ # @param [CacheStoreDatabase] database
198+ # @return [nil]
199+ sig { params ( database : CacheStoreDatabase ) . void }
193200 def initialize ( database )
194201 @database = database
195202 end
196203
197204 protected
198205
199- sig { returns ( CacheStoreDatabase [ Key , Value ] ) }
206+ # @return [CacheStoreDatabase]
207+ sig { returns ( CacheStoreDatabase ) }
200208 attr_reader :database
201209end
0 commit comments