class ZAWS::Repository::Filestore

Attributes

location[RW]
timeout[RW]

Public Class Methods

new(empty=false) click to toggle source
# File lib/zaws/helper/filestore.rb, line 11
def initialize(empty=false)
  @empty=empty
end

Public Instance Methods

retrieve(key,command=nil) click to toggle source
# File lib/zaws/helper/filestore.rb, line 31
def retrieve(key,command=nil)
  return if @empty
  if command.nil?
     filename=key
  else
     filename=key+Digest::MD5.hexdigest(command)
  end
  if File.exists?("#{@location}/#{filename}")
    storage = YAML.load(File.read("#{@location}/#{filename}"))
    if storage['expires'].to_i > Time.now.to_i
      return storage['value']
    end
  end
end
store(key,value,expires,command=nil) click to toggle source
# File lib/zaws/helper/filestore.rb, line 15
def store(key,value,expires,command=nil)
  return if @empty
   storage = {}
   storage['value']=value
   storage['expires']=expires.strftime('%s')
   if command.nil?
     filename=key
   else
     storage['command']=command
     filename=key+Digest::MD5.hexdigest(command)
   end
   File.open("#{@location}/#{filename}","w") do |file|
     file.write storage.to_yaml
   end
end