Sha256: 0b5b3b055a205095ae4a888c63b6a7de379dec7c21dc0f682a4c3807639bb825
Contents?: true
Size: 1.14 KB
Versions: 2
Compression:
Stored size: 1.14 KB
Contents
# Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com # All files in this distribution are subject to the terms of the Ruby license. require 'yaml/store' module Ramaze class YAMLStoreCache attr_accessor :file # create a new YAML::Store with the given file (which will be created if it # is not already there). def initialize(file = 'cache.yaml') @file = file @cache = YAML::Store.new(file) end # return the values for given keys. def values_at(*keys) transaction do |y| keys.map{|k| y[k]} end end def underlying_yaml YAML.load_file(@file) end def clear transaction do |y| File.open(@file, 'w+'){|f| f.puts({}.to_yaml)} end end def delete(key) transaction do |y| y.delete(key) end end # just a helper to use transactions. def transaction(&block) @cache.transaction do yield(@cache) end end # catch everything else and use a transaction to send it. def method_missing(*args, &block) transaction do |y| y.send(*args, &block) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ramaze-0.1.1 | lib/ramaze/cache/yaml_store.rb |
ramaze-0.1.2 | lib/ramaze/cache/yaml_store.rb |