/usr/lib/ruby/1.8/moneta/yaml.rb is in libmoneta-ruby1.8 0.6.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | require "yaml"
require "fileutils"
module Moneta
class YAML
class Expiration
def initialize(file)
@file = file
end
def [](key)
yaml[key]['expires'] if yaml.has_key?(key)
end
def []=(key, value)
hash = yaml
if hash.has_key?(key)
hash[key]['expires'] = value
save(hash)
end
end
def delete(key)
hash = yaml
if hash.has_key?(key)
hash[key].delete("expires")
save(hash)
end
end
private
def yaml
::YAML.load_file(@file)
end
def save(hash)
::File.open(@file, "w") { |file| file << hash.to_yaml }
end
end
def initialize(options = {})
@file = File.expand_path(options[:path])
unless ::File.exists?(@file)
File.open(@file, "w") { |file| file << {}.to_yaml }
end
@expiration = Expiration.new(@file)
end
module Implementation
def key?(key)
yaml.has_key?(key)
end
alias has_key? key?
def [](key)
yaml[key]['value'] if yaml.has_key?(key)
end
def []=(key, value)
hash = yaml
(hash[key] ||= {})['value'] = value
save(hash)
end
def delete(key)
hash = yaml
value = self[key]
hash.delete(key)
save(hash)
value
end
def clear
save
end
private
def yaml
::YAML.load_file(@file)
end
def save(hash = {})
::File.open(@file, "w") { |file| file << hash.to_yaml }
end
end
include Implementation
include Defaults
include Expires
end
end
|