Module: ShafClient::HypertextCacheStrategy
- Included in:
- ShafClient
- Defined in:
- lib/shaf_client/hypertext_cache_strategy.rb
Constant Summary collapse
- AVAILABLE_CACHE_STRATEGIES =
[ CACHE_STRATEGY_NO_CACHE = :no_cache, CACHE_STRATEGY_EMBEDDED = :use_embedded, CACHE_STRATEGY_FETCH_HEADERS = :fetch_headers ]
Class Method Summary collapse
- .cacheable?(strategy) ⇒ Boolean
- .default_headers ⇒ Object
- .default_http_status ⇒ Object
- .fetch_headers?(strategy) ⇒ Boolean
Instance Method Summary collapse
Class Method Details
.cacheable?(strategy) ⇒ Boolean
10 11 12 |
# File 'lib/shaf_client/hypertext_cache_strategy.rb', line 10 def cacheable?(strategy) [CACHE_STRATEGY_EMBEDDED, CACHE_STRATEGY_FETCH_HEADERS].include? strategy end |
.default_headers ⇒ Object
22 23 24 |
# File 'lib/shaf_client/hypertext_cache_strategy.rb', line 22 def default_headers {'content-type' => 'application/hal+json'} end |
.default_http_status ⇒ Object
18 19 20 |
# File 'lib/shaf_client/hypertext_cache_strategy.rb', line 18 def default_http_status 203 end |
.fetch_headers?(strategy) ⇒ Boolean
14 15 16 |
# File 'lib/shaf_client/hypertext_cache_strategy.rb', line 14 def fetch_headers?(strategy) CACHE_STRATEGY_FETCH_HEADERS == strategy end |
Instance Method Details
#default_hypertext_cache_strategy ⇒ Object
27 28 29 |
# File 'lib/shaf_client/hypertext_cache_strategy.rb', line 27 def default_hypertext_cache_strategy @__default_hypertext_cache_strategy ||= CACHE_STRATEGY_EMBEDDED end |
#default_hypertext_cache_strategy=(strategy) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/shaf_client/hypertext_cache_strategy.rb', line 31 def default_hypertext_cache_strategy=(strategy) unless __valid_cache? strategy raise Error, <<~ERR Unsupported hypertext cache strategy: #{strategy} Possible strategies are: #{AVAILABLE_CACHE_STRATEGIES.join(', ')} ERR end @__default_hypertext_cache_strategy = value end |