Skip to content

Commit

Permalink
Support DB#increment.
Browse files Browse the repository at this point in the history
  • Loading branch information
csw committed Jun 27, 2012
1 parent 3f10f78 commit c3fde46
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
5 changes: 5 additions & 0 deletions lib/kyotocabinet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ def get(key)
end
alias_method :[], :get

alias_method :_increment, :increment
def increment(key, num=0, orig=0)
self._increment(key, num, orig)
end

alias_method :_set, :set
def set(k, v)
self._set(k.to_java_bytes, v.to_s.to_java_bytes)
Expand Down
19 changes: 17 additions & 2 deletions spec/kyotocabinet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,25 @@ module KyotoCabinet
@db = DB.new
@db.open("%", KyotoCabinet::DB::OWRITER | KyotoCabinet::DB::OCREATE)
@db["hello"] = "world"
@db["int_a"] = [0].pack("Q>")
end

it "returns nil from get properly" do
@db.get("foo").should be_nil
describe "#get" do
it "returns nil properly" do
@db.get("foo").should be_nil
end
end

describe "#increment" do
it "creates a value with one arg" do
@db.increment("int_z")
@db["int_z"].should_not be_nil
end

it "increments with two args" do
@db.increment("int_a", 1)
@db["int_a"].unpack("Q>")[0].should == 1
end
end

after(:each) do
Expand Down

0 comments on commit c3fde46

Please sign in to comment.