Class: AppStore::Emigrant::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/app-store-emigrant/cache.rb

Overview

Cache mechanism

Constant Summary collapse

LOCATION =
begin
  path = Pathname.new('~/.ase-cache').expand_path
  unless path.directory?
    path.mkpath
  end
  path
end

Class Method Summary collapse

Class Method Details

.clear!Object

Forcefully clears the cache



29
30
31
32
33
# File 'lib/app-store-emigrant/cache.rb', line 29

def self.clear!
  LOCATION.children.each do |item|
    item.delete if item.file?
  end
end

.countObject

Number of items in the cache



36
37
38
# File 'lib/app-store-emigrant/cache.rb', line 36

def self.count
  LOCATION.children.select { |item| item.file? }.length
end

.has?(item) ⇒ Boolean

Whether cache has this item

Returns:

  • (Boolean)


19
20
21
# File 'lib/app-store-emigrant/cache.rb', line 19

def self.has? item
  LOCATION.join(item).file?
end

.path_to(item) ⇒ Object

Path to given item (whether existent or not)



24
25
26
# File 'lib/app-store-emigrant/cache.rb', line 24

def self.path_to item
  LOCATION.join(item).to_s
end