Class: FileCache

Inherits:
Object show all
Defined in:
lib/file_cache.rb

Constant Summary collapse

MAXDURATION =
60 * 10

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filepath) ⇒ FileCache



12
13
14
# File 'lib/file_cache.rb', line 12

def initialize(filepath)
  @filepath = filepath
end

Instance Attribute Details

#filepathObject (readonly)

Returns the value of attribute filepath.



11
12
13
# File 'lib/file_cache.rb', line 11

def filepath
  @filepath
end

Class Method Details

.get(filepath, &blk) ⇒ Object



7
8
9
# File 'lib/file_cache.rb', line 7

def self.get(filepath, &blk)
  new(filepath).cache!(&blk)
end

Instance Method Details

#cache!Object



16
17
18
19
20
# File 'lib/file_cache.rb', line 16

def cache!
  return read_cache if cached?

  yield.tap { write_cache(_1) }
end