Class: IMP3::Cache

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/imp3/cache.rb

Constant Summary collapse

CACHE_FILE =
File.join(IMP3::APP_DIR, "cache.yml")

Instance Method Summary collapse

Constructor Details

#initializeCache

Returns a new instance of Cache.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/imp3/cache.rb', line 8

def initialize
  @data = {}

  if File.exist?(CACHE_FILE)
    begin
      @data = YAML.load_file(CACHE_FILE)
    rescue
      raise "Unable to read cache file #{CACHE_FILE}"
    end
  end
end

Instance Method Details

#artist_genresObject



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

def artist_genres
  @data[:artist_genres] ||= {}
  @data[:artist_genres]
end

#saveObject



25
26
27
# File 'lib/imp3/cache.rb', line 25

def save
  File.new(CACHE_FILE, "w+").write(@data.to_yaml)
end