Class: Terminalwire::Cache::File::Store

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/terminalwire/cache.rb

Instance Method Summary collapse

Constructor Details

#initialize(path:) ⇒ Store

Returns a new instance of Store.



16
17
18
19
# File 'lib/terminalwire/cache.rb', line 16

def initialize(path:)
  @path = Pathname.new(path).expand_path
  FileUtils.mkdir_p(@path) unless @path.directory?
end

Instance Method Details

#destroyObject



30
31
32
# File 'lib/terminalwire/cache.rb', line 30

def destroy
  each(&:destroy)
end

#eachObject



34
35
36
37
38
# File 'lib/terminalwire/cache.rb', line 34

def each
  @path.each_child do |path|
    yield Entry.new(path:)
  end
end

#entry(key) ⇒ Object Also known as: []



21
22
23
# File 'lib/terminalwire/cache.rb', line 21

def entry(key)
  Entry.new(path: @path.join(Entry.key_path(key)))
end

#evictObject



26
27
28
# File 'lib/terminalwire/cache.rb', line 26

def evict
  each(&:evict)
end