Class: Moneta::Couch
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #clear ⇒ Object
- #delete(key) ⇒ Object
- #delete_store ⇒ Object
-
#initialize(options = {}) ⇒ Couch
constructor
A new instance of Couch.
- #key?(key) ⇒ Boolean (also: #has_key?)
- #update_key(key, options = {}) ⇒ Object
Methods included from Defaults
Constructor Details
#initialize(options = {}) ⇒ Couch
Returns a new instance of Couch.
12 13 14 15 16 17 18 |
# File 'lib/moneta/couch.rb', line 12 def initialize( = {}) @db = ::CouchRest.database!([:db]) unless [:skip_expires] @expiration = Moneta::Couch.new(:db => "#{[:db]}_expiration", :skip_expires => true) self.extend(StringExpires) end end |
Instance Method Details
#[](key) ⇒ Object
28 29 30 31 32 |
# File 'lib/moneta/couch.rb', line 28 def [](key) @db.get(key)["data"] rescue RestClient::ResourceNotFound nil end |
#[]=(key, value) ⇒ Object
34 35 36 37 38 |
# File 'lib/moneta/couch.rb', line 34 def []=(key, value) @db.save_doc("_id" => key, :data => value) rescue RestClient::RequestFailed self[key] end |
#clear ⇒ Object
55 56 57 |
# File 'lib/moneta/couch.rb', line 55 def clear @db.recreate! end |
#delete(key) ⇒ Object
40 41 42 43 44 45 46 |
# 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 ⇒ Object
59 60 61 |
# File 'lib/moneta/couch.rb', line 59 def delete_store @db.delete! end |
#key?(key) ⇒ Boolean Also known as: has_key?
20 21 22 23 24 |
# File 'lib/moneta/couch.rb', line 20 def key?(key) !self[key].nil? rescue RestClient::ResourceNotFound false end |
#update_key(key, options = {}) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/moneta/couch.rb', line 48 def update_key(key, = {}) val = self[key] self.store(key, val, ) rescue RestClient::ResourceNotFound nil end |