Skip to content

Commit

Permalink
Make CacheableRegistry strictly typed
Browse files Browse the repository at this point in the history
This changes the typed mode for this module from
'true' to 'strict', which requires annotations
for methods and variables.
  • Loading branch information
bilbof committed Jun 20, 2019
1 parent 6c0f54c commit cdeaeef
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/lib/registries/cacheable_registry.rb
@@ -1,19 +1,23 @@
# typed: true
# typed: strict
module Registries
module CacheableRegistry
extend T::Sig
include Kernel

sig {returns(TrueClass)}
def can_refresh_cache?
true
end

sig {returns(T::Boolean)}
def refresh_cache
Rails.cache.write(cache_key, cacheable_data)
rescue GdsApi::HTTPServerError, GdsApi::HTTPBadGateway
report_error
false
end

sig {returns(T::Hash)}
def fetch_from_cache
Rails.cache.fetch(cache_key) do
cacheable_data
Expand All @@ -23,14 +27,17 @@ def fetch_from_cache
{}
end

sig {void}
def cacheable_data
raise NotImplementedError, "Please supply a cacheable_data method"
end

sig {void}
def cache_key
raise NotImplementedError, "Please supply a cache_key method"
end

sig {void}
def report_error
raise NotImplementedError, "Please supply a report_error method"
end
Expand Down

0 comments on commit cdeaeef

Please sign in to comment.