Class: Cache
- Inherits:
-
Object
- Object
- Cache
- Defined in:
- lib/shilling/cache.rb
Instance Method Summary collapse
-
#initialize(name) ⇒ Cache
constructor
A new instance of Cache.
- #read ⇒ Object
- #write(data) ⇒ Object
Constructor Details
#initialize(name) ⇒ Cache
Returns a new instance of Cache.
4 5 6 |
# File 'lib/shilling/cache.rb', line 4 def initialize( name ) @name = name end |
Instance Method Details
#read ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/shilling/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/shilling/cache.rb', line 8 def write( data ) File.open( @name, 'w:utf-8' ) do |f| f.write JSON.pretty_generate( data ) end end |