Module: RailsI18nterface::Cache

Included in:
Sourcefiles
Defined in:
lib/rails-i18nterface/cache.rb

Instance Method Summary collapse

Instance Method Details

#cache_load(uri, options = {}, &process) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/rails-i18nterface/cache.rb', line 14

def cache_load(uri, options = {}, &process)
  if File.exists? uri
    load uri
  elsif block_given?
    cache_save(yield(options), uri)
  else
    nil
  end
end

#cache_save(obj, uri) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/rails-i18nterface/cache.rb', line 6

def cache_save(obj, uri)
  FileUtils.rm uri if File.exists? uri
  File.open(uri, 'wb') do |f|
    Marshal.dump(obj, f)
  end
  obj
end