Class: ReevooMark::Cache::Entry
- Inherits:
-
Object
- Object
- ReevooMark::Cache::Entry
- Defined in:
- lib/reevoomark/cache/entry.rb
Instance Attribute Summary collapse
-
#cache_path ⇒ Object
readonly
Returns the value of attribute cache_path.
Instance Method Summary collapse
- #document ⇒ Object
- #document=(doc) ⇒ Object
- #exists? ⇒ Boolean
- #expired? ⇒ Boolean
-
#initialize(cache_path) ⇒ Entry
constructor
A new instance of Entry.
- #revalidate_for(max_age) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(cache_path) ⇒ Entry
Returns a new instance of Entry.
4 5 6 |
# File 'lib/reevoomark/cache/entry.rb', line 4 def initialize(cache_path) @cache_path = Pathname.new(cache_path) end |
Instance Attribute Details
#cache_path ⇒ Object (readonly)
Returns the value of attribute cache_path.
2 3 4 |
# File 'lib/reevoomark/cache/entry.rb', line 2 def cache_path @cache_path end |
Instance Method Details
#document ⇒ Object
20 21 22 23 |
# File 'lib/reevoomark/cache/entry.rb', line 20 def document raise "Loading from cache, where no cache exists is bad." unless exists? @document ||= YAML.load(read) end |
#document=(doc) ⇒ Object
25 26 27 28 29 |
# File 'lib/reevoomark/cache/entry.rb', line 25 def document= doc @document = nil # Flush the memoized value write doc.to_yaml doc end |
#exists? ⇒ Boolean
8 9 10 |
# File 'lib/reevoomark/cache/entry.rb', line 8 def exists? @cache_path.exist? end |
#expired? ⇒ Boolean
12 13 14 |
# File 'lib/reevoomark/cache/entry.rb', line 12 def expired? document.expired? end |
#revalidate_for(max_age) ⇒ Object
31 32 33 34 35 |
# File 'lib/reevoomark/cache/entry.rb', line 31 def revalidate_for(max_age) if exists? self.document = document.revalidated_for(max_age) end end |
#valid? ⇒ Boolean
16 17 18 |
# File 'lib/reevoomark/cache/entry.rb', line 16 def valid? exists? and not expired? end |