Class: Moneta::Adapters::Couch
- Inherits:
-
Object
- Object
- Moneta::Adapters::Couch
- Includes:
- Defaults
- Defined in:
- lib/moneta/adapters/couch.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #clear ⇒ Object
- #delete(key) ⇒ Object
-
#initialize(options = {}) ⇒ Couch
constructor
A new instance of Couch.
- #key?(key) ⇒ Boolean
- #store(key, value) ⇒ Object
Methods included from Defaults
Constructor Details
#initialize(options = {}) ⇒ Couch
Returns a new instance of Couch.
13 14 15 |
# File 'lib/moneta/adapters/couch.rb', line 13 def initialize( = {}) @db = ::CouchRest.database!([:db]) end |
Instance Method Details
#[](key) ⇒ Object
23 24 25 26 27 |
# File 'lib/moneta/adapters/couch.rb', line 23 def [](key) deserialize(@db.get(key_for(key))["data"]) rescue RestClient::ResourceNotFound nil end |
#clear ⇒ Object
46 47 48 |
# File 'lib/moneta/adapters/couch.rb', line 46 def clear(*) @db.recreate! end |
#delete(key) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/moneta/adapters/couch.rb', line 35 def delete(key, *) value = @db.get(key_for(key)) if value @db.delete_doc({"_id" => value["_id"], "_rev" => value["_rev"]}) if value deserialize(value["data"]) end rescue RestClient::ResourceNotFound nil end |
#key?(key) ⇒ Boolean
17 18 19 20 21 |
# File 'lib/moneta/adapters/couch.rb', line 17 def key?(key, *) !self[key_for(key)].nil? rescue RestClient::ResourceNotFound false end |
#store(key, value) ⇒ Object
29 30 31 32 33 |
# File 'lib/moneta/adapters/couch.rb', line 29 def store(key, value, *) @db.save_doc("_id" => key_for(key), :data => serialize(value)) rescue RestClient::RequestFailed self[key_for(key)] end |