Sha256: 64768087d5626ecfe1e9c2f0af839db3ee82a3e5a49c1a5eec818e9dc007151d

Contents?: true

Size: 1.24 KB

Versions: 18

Compression:

Stored size: 1.24 KB

Contents

begin
  require "couchrest"
rescue LoadError
  puts "You need the couchrest gem to use the CouchDB store"
  exit
end

module Moneta
  class Couch
    include Defaults
    
    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

    def key?(key)
      !self[key].nil?
    rescue RestClient::ResourceNotFound
      false
    end

    alias has_key? key?

    def [](key)
      @db.get(key)["data"]
    rescue RestClient::ResourceNotFound
      nil
    end

    def []=(key, value)
      @db.save_doc("_id" => key, :data => value)
    rescue RestClient::RequestFailed
      self[key]
    end

    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

    def update_key(key, options = {})
      val = self[key]
      self.store(key, val, options)
    rescue RestClient::ResourceNotFound
      nil
    end

    def clear
      @db.recreate!
    end

    def delete_store
      @db.delete!
    end
  end
end

Version data entries

18 entries across 18 versions & 9 rubygems

Version Path
aeden-moneta-0.6.2 lib/moneta/couch.rb
aeden-moneta-0.6.3 lib/moneta/couch.rb
benschwarz-moneta-0.6.1 lib/moneta/couch.rb
benschwarz-smoke-0.5.0 vendor/moneta/lib/moneta/couch.rb
benschwarz-smoke-0.5.1 vendor/moneta/lib/moneta/couch.rb
benschwarz-smoke-0.5.2 vendor/moneta/lib/moneta/couch.rb
benschwarz-smoke-0.5.3 vendor/moneta/lib/moneta/couch.rb
benschwarz-smoke-0.5.4 vendor/moneta/lib/moneta/couch.rb
benschwarz-smoke-0.5.5 vendor/moneta/lib/moneta/couch.rb
benschwarz-smoke-0.5.6 vendor/moneta/lib/moneta/couch.rb
jferris-moneta-0.6.2 lib/moneta/couch.rb
jsl-moneta-0.6.1 lib/moneta/couch.rb
jsl-moneta-0.6.2 lib/moneta/couch.rb
jsl-moneta-0.6.3 lib/moneta/couch.rb
smurphy-moneta-0.6.0 lib/moneta/couch.rb
gotime-moneta-0.6.2 lib/moneta/couch.rb
thoughtless-moneta-0.6.0.1 lib/moneta/couch.rb
moneta-0.6.0 lib/moneta/couch.rb