Class: Cache

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

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Cache

Returns a new instance of Cache.



4
5
6
# File 'lib/centralbank/cache.rb', line 4

def initialize( name )
  @name = name
end

Instance Method Details

#readObject



14
15
16
17
18
19
20
21
# File 'lib/centralbank/cache.rb', line 14

def read
  if File.exists?( @name )
    data = File.open( @name, 'r:bom|utf-8' ).read
    JSON.parse( data )
  else
    nil
  end
end

#write(data) ⇒ Object



8
9
10
11
12
# File 'lib/centralbank/cache.rb', line 8

def write( data )
  File.open( @name, 'w:utf-8' ) do |f|
    f.write JSON.pretty_generate( data )
  end
end