Sha256: 1925acaa935428f9ee2cc6c0f4d2d522bc7b08ddca48abcbdbcfb42e61978dcd

Contents?: true

Size: 528 Bytes

Versions: 4

Compression:

Stored size: 528 Bytes

Contents

# encoding: utf-8

module RailsI18nterface
  module Cache

    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

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

    private

    def load(uri)
      File.open(uri) do |f|
        Marshal.load f
      end
    end


  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rails-i18nterface-0.2.4 lib/rails-i18nterface/cache.rb
rails-i18nterface-0.2.3 lib/rails-i18nterface/cache.rb
rails-i18nterface-0.2.2 lib/rails-i18nterface/cache.rb
rails-i18nterface-0.2.1 lib/rails-i18nterface/cache.rb