lib/rufus/edo/cabcore.rb in rufus-tokyo-0.1.13 vs lib/rufus/edo/cabcore.rb in rufus-tokyo-0.1.14

- old
+ new

@@ -186,47 +186,67 @@ # Deletes all the entries whose keys begin with the given prefix # def delete_keys_with_prefix (prefix) - #call_misc('outlist', lib.abs_fwmkeys2(@db, prefix, -1)) - # # -1 for no limits - @db.fwmkeys(prefix, -1).each { |k| self.delete(k) } + # only ADB has the #misc method... + + if @db.respond_to?(:misc) + @db.misc('outlist', @db.fwmkeys(prefix, -1)) + else + @db.fwmkeys(prefix, -1).each { |k| self.delete(k) } + end + nil end # Given a list of keys, returns a Hash { key => value } of the # matching entries (in one sweep). # # Warning : this is a naive (slow) implementation. # def lget (keys) - #Hash[*call_misc('getlist', Rufus::Tokyo::List.new(keys))] - keys.inject({}) { |h, k| v = self[k]; h[k] = v if v; h } + # only ADB has the #misc method... + + if @db.respond_to?(:misc) + Hash[*@db.misc('getlist', keys)] + else + keys.inject({}) { |h, k| v = self[k]; h[k] = v if v; h } + end end - #-- + # # default impl provided by HashMethods # - #def merge! (hash) - # call_misc( - # 'putlist', - # hash.inject(Rufus::Tokyo::List.new) { |l, (k, v)| l << k; l << v; l }) - # self - #end - #++ + def merge! (hash) + + # only ADB has the #misc method... + + if @db.respond_to?(:misc) + @db.misc('putlist', hash.to_a.flatten) + else + super(hash) + end + self + end alias :lput :merge! # Given a list of keys, deletes all the matching entries (in one sweep). # # Warning : this is a naive (slow) implementation. # def ldelete (keys) - #call_misc('outlist', Rufus::Tokyo::List.new(keys)) - keys.each { |k| self.delete(k) } + # only ADB has the #misc method... + + if @db.respond_to?(:misc) + @db.misc('outlist', keys) + else + keys.each { |k| self.delete(k) } + end + nil end # Increments the value stored under the given key with the given increment # (defaults to 1 (integer)). @@ -244,9 +264,20 @@ end alias :adddouble :incr alias :addint :incr alias :add_double :incr alias :add_int :incr + + # Triggers a defrag (TC >= 1.4.21 only) + # + def defrag + + raise(NotImplementedError.new( + "defrag (misc) only available when opening db with :type => :abstract" + )) unless @db.respond_to?(:misc) + + @db.misc('defrag', []) + end # Returns the underlying 'native' Ruby object (of the class devised by # Hirabayashi-san) # def original