Class: ZAWS::Repository::Filestore
- Inherits:
-
Object
- Object
- ZAWS::Repository::Filestore
- Defined in:
- lib/zaws/helper/filestore.rb
Instance Attribute Summary collapse
-
#location ⇒ Object
Returns the value of attribute location.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#initialize(empty = false) ⇒ Filestore
constructor
A new instance of Filestore.
- #retrieve(key, command = nil) ⇒ Object
- #store(key, value, expires, command = nil) ⇒ Object
Constructor Details
#initialize(empty = false) ⇒ Filestore
Returns a new instance of Filestore.
11 12 13 |
# File 'lib/zaws/helper/filestore.rb', line 11 def initialize(empty=false) @empty=empty end |
Instance Attribute Details
#location ⇒ Object
Returns the value of attribute location.
8 9 10 |
# File 'lib/zaws/helper/filestore.rb', line 8 def location @location end |
#timeout ⇒ Object
Returns the value of attribute timeout.
9 10 11 |
# File 'lib/zaws/helper/filestore.rb', line 9 def timeout @timeout end |
Instance Method Details
#retrieve(key, command = nil) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# 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) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# 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 |