Sha256: 54cb8976b1f8310ed4079d7c72a64d0684246c551c91d217c112a1b39c480df7

Contents?: true

Size: 930 Bytes

Versions: 18

Compression:

Stored size: 930 Bytes

Contents

begin
  require 'bdb'
rescue LoadError
  puts "You need bdb gem to use Bdb moneta store"
  exit
end

module Moneta

  class Berkeley
    include Defaults

    def initialize(options={})
      file = @file = options[:file]
      @db = Bdb::Db.new()
      @db.open(nil, file, nil, Bdb::Db::BTREE, Bdb::DB_CREATE, 0)
      unless options[:skip_expires]
        @expiration = Moneta::Berkeley.new(:file => "#{file}_expiration", :skip_expires => true )
        self.extend(StringExpires)
      end
    end
    
    module Implementation
      def key?(key)
        nil | self[key]
      end

      alias has_key? key?

      def []=(key,value)
        @db[key] = value
      end

      def [](key)
        @db[key]
      end

      def delete(key)
        value = self[key]
        @db.del(nil,key,0) if value
        value
      end

      def clear
        @db.truncate(nil)
      end
    end

    include Implementation

  end

end

Version data entries

18 entries across 18 versions & 9 rubygems

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