@@ -244,19 +244,36 @@ def to_resource_shim(resource)
244
244
type_definition . create_attribute_in ( self , name , param_or_property , parent , options )
245
245
end
246
246
247
+ def self . rsapi_provider_get ( names = [ ] )
248
+ # If the cache has been marked as having all instances, then just return the
249
+ # full contents:
250
+ return rsapi_provider_get_cache . all if rsapi_provider_get_cache . cached_all? && names . empty?
251
+
252
+ fetched = if type_definition . feature? ( 'simple_get_filter' )
253
+ my_provider . get ( context , names )
254
+ else
255
+ my_provider . get ( context )
256
+ end
257
+
258
+ fetched . each do |resource_hash |
259
+ type_definition . check_schema ( resource_hash )
260
+ rsapi_provider_get_cache . add ( build_title ( type_definition , resource_hash ) , resource_hash )
261
+ end
262
+
263
+ if !type_definition . feature? ( 'simple_get_filter' ) || names . empty?
264
+ # Mark the cache as having all possible instances:
265
+ rsapi_provider_get_cache . cached_all
266
+ end
267
+
268
+ fetched
269
+ end
270
+
247
271
def self . instances
248
272
# puts 'instances'
249
273
# force autoloading of the provider
250
274
provider ( type_definition . name )
251
275
252
- initial_fetch = if type_definition . feature? ( 'simple_get_filter' )
253
- my_provider . get ( context , [ ] )
254
- else
255
- my_provider . get ( context )
256
- end
257
-
258
- initial_fetch . map do |resource_hash |
259
- type_definition . check_schema ( resource_hash )
276
+ rsapi_provider_get . map do |resource_hash |
260
277
# allow a :title from the provider to override the default
261
278
result = if resource_hash . key? :title
262
279
new ( title : resource_hash [ :title ] )
@@ -271,14 +288,9 @@ def self.instances
271
288
end
272
289
273
290
def refresh_current_state
274
- current_state = if type_definition . feature? ( 'simple_get_filter' )
275
- my_provider . get ( context , [ rsapi_title ] ) . find { |h | namevar_match? ( h ) }
276
- else
277
- my_provider . get ( context ) . find { |h | namevar_match? ( h ) }
278
- end
291
+ current_state = self . class . rsapi_provider_get ( [ rsapi_title ] ) . find { |h | namevar_match? ( h ) }
279
292
280
293
if current_state
281
- type_definition . check_schema ( current_state )
282
294
strict_check ( current_state )
283
295
else
284
296
current_state = if rsapi_title . is_a? Hash
0 commit comments