class Moneta::Couch
Public Class Methods
new(options = {})
click to toggle source
# File lib/moneta/couch.rb, line 12 def initialize(options = {}) @db = ::CouchRest.database!(options[:db]) unless options[:skip_expires] @expiration = Moneta::Couch.new(:db => "#{options[:db]}_expiration", :skip_expires => true) self.extend(StringExpires) end end
Public Instance Methods
[](key)
click to toggle source
# File lib/moneta/couch.rb, line 28 def [](key) @db.get(key)["data"] rescue RestClient::ResourceNotFound nil end
[]=(key, value)
click to toggle source
# File lib/moneta/couch.rb, line 34 def []=(key, value) @db.save_doc("_id" => key, :data => value) rescue RestClient::RequestFailed self[key] end
clear()
click to toggle source
# File lib/moneta/couch.rb, line 55 def clear @db.recreate! end
delete(key)
click to toggle source
# File lib/moneta/couch.rb, line 40 def delete(key) value = @db.get(key) @db.delete_doc({"_id" => value["_id"], "_rev" => value["_rev"]}) if value value["data"] rescue RestClient::ResourceNotFound nil end
delete_store()
click to toggle source
# File lib/moneta/couch.rb, line 59 def delete_store @db.delete! end
key?(key)
click to toggle source
# File lib/moneta/couch.rb, line 20 def key?(key) !self[key].nil? rescue RestClient::ResourceNotFound false end
Also aliased as: has_key?
update_key(key, options = {})
click to toggle source
# File lib/moneta/couch.rb, line 48 def update_key(key, options = {}) val = self[key] self.store(key, val, options) rescue RestClient::ResourceNotFound nil end