Class: ReevooMark::Cache::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/reevoomark/cache/entry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_pathObject (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

#documentObject



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

Returns:

  • (Boolean)


8
9
10
# File 'lib/reevoomark/cache/entry.rb', line 8

def exists?
  @cache_path.exist?
end

#expired?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


16
17
18
# File 'lib/reevoomark/cache/entry.rb', line 16

def valid?
  exists? and not expired?
end