Class: Gister::Fetcher
- Inherits:
-
Object
- Object
- Gister::Fetcher
- Defined in:
- lib/gister/fetcher.rb
Defined Under Namespace
Classes: MemoryStore
Constant Summary collapse
- ClientError =
Class.new(StandardError)
- GistNotFound =
Class.new(ClientError)
Instance Attribute Summary collapse
-
#store ⇒ Object
writeonly
Sets the attribute store.
Instance Method Summary collapse
- #fetch(key) ⇒ Object
- #get(k) ⇒ Object
-
#initialize(store = MemoryStore.new) ⇒ Fetcher
constructor
A new instance of Fetcher.
- #set(k, v) ⇒ Object
Constructor Details
#initialize(store = MemoryStore.new) ⇒ Fetcher
Returns a new instance of Fetcher.
16 17 18 |
# File 'lib/gister/fetcher.rb', line 16 def initialize(store = MemoryStore.new) @store = store end |
Instance Attribute Details
#store=(value) ⇒ Object (writeonly)
Sets the attribute store
14 15 16 |
# File 'lib/gister/fetcher.rb', line 14 def store=(value) @store = value end |
Instance Method Details
#fetch(key) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/gister/fetcher.rb', line 20 def fetch(key) if result = get(key) result else result = fetch_result(key) set key, result result end end |
#get(k) ⇒ Object
30 |
# File 'lib/gister/fetcher.rb', line 30 def get(k); @store.get(cache_bust(k)); end |
#set(k, v) ⇒ Object
31 |
# File 'lib/gister/fetcher.rb', line 31 def set(k, v); @store.set(cache_bust(k), v); end |