Class: Arstotzka::Fetcher::Cache Private
- Inherits:
-
Object
- Object
- Arstotzka::Fetcher::Cache
- Includes:
- Base
- Defined in:
- lib/arstotzka/fetcher/cache.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Class responsible for reading instance variables when cached option is given.
When the “cache” is not accepted, block will be called to determinate the value to be returned also caching it in an instance variable
Instance Attribute Summary collapse
- #block ⇒ Object readonly private private
- #options ⇒ Object readonly private private
Instance Method Summary collapse
-
#fetch { ... } ⇒ Object
private
Fetches value from instance or block.
-
#initialize(options_hash = {}, &block) ⇒ Cache
constructor
private
A new instance of Cache.
Methods included from Base
Constructor Details
#initialize(options, &block) ⇒ Cache #initialize(options_hash, &block) ⇒ Cache
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Cache.
26 27 28 29 |
# File 'lib/arstotzka/fetcher/cache.rb', line 26 def initialize( = {}, &block) self. = @block = block end |
Instance Attribute Details
#block ⇒ Object (readonly, private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
105 106 107 |
# File 'lib/arstotzka/fetcher/cache.rb', line 105 def block @block end |
#options ⇒ Object (readonly, private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
105 106 107 |
# File 'lib/arstotzka/fetcher/cache.rb', line 105 def @options end |
Instance Method Details
#fetch { ... } ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Fetches value from instance or block
When cached option is given, fetches value from cache, and in case of failure, retrieves value from block given in the initialization
95 96 97 98 99 100 101 |
# File 'lib/arstotzka/fetcher/cache.rb', line 95 def fetch if cached fetch_with_cache else block.call end end |