Sha256: 6556c7b570e02d04765798d2f10faec24d8ec82cca90420a8613e0d9a7e4a373

Contents?: true

Size: 1.22 KB

Versions: 16

Compression:

Stored size: 1.22 KB

Contents

module Monkeyshines
  module Store
    class KeyStore < Monkeyshines::Store::Base
      # The actual backing store; should respond to #set and #get methods
      attr_accessor :db

      #
      # Executes block once for each element in the whole DB, in whatever order
      # the DB thinks you should see it.
      #
      # Your block will see |key, val|
      #
      # key_store.each do |key, val|
      #   # ... stuff ...
      # end
      #
      def each &block
        db.iterinit
        loop do
          key = db.iternext or break
          val = db[key]
          yield key, val
        end
      end


      # Save the value into the database
      def set(key, val)
        return unless val
        db[key] = val
      end

      alias_method :save, :set
      def get(key)      db[key]  end
      def [](key)       db[key]  end
      def close()       db.close end
      def size()        db.size  end

      #
      # Load from standard command-line options
      #
      # obvs only works when there's just one store
      #
      def self.new_from_command_line cmdline_opts, default_opts={}
        options = default_opts.merge(cmdline_opts)
        store = self.new(options[:store_db])
        store
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
wukong-3.0.0.pre old/wukong/store/key_store.rb
wukong-2.0.2 lib/wukong/store/key_store.rb
wukong-2.0.1 lib/wukong/store/key_store.rb
wukong-2.0.0 lib/wukong/store/key_store.rb
wukong-1.5.4 lib/wukong/store/key_store.rb
wukong-1.5.3 lib/wukong/store/key_store.rb
wukong-1.5.2 lib/wukong/store/key_store.rb
wukong-1.5.1 lib/wukong/store/key_store.rb
wukong-1.5.0 lib/wukong/store/key_store.rb
wukong-1.4.12 lib/wukong/store/key_store.rb
wukong-1.4.11 lib/wukong/store/key_store.rb
monkeyshines-0.2.3 lib/monkeyshines/store/key_store.rb
monkeyshines-0.2.2 lib/monkeyshines/store/key_store.rb
monkeyshines-0.2.1 lib/monkeyshines/store/key_store.rb
monkeyshines-0.2.0 lib/monkeyshines/store/key_store.rb
monkeyshines-0.0.2 lib/monkeyshines/store/key_store.rb