Skip to content

Commit

Permalink
added #putdup and #get4 to Rufus::Edo::Cabinet
Browse files Browse the repository at this point in the history
  • Loading branch information
jmettraux committed Aug 28, 2009
1 parent 2b8a934 commit 1ff4ed0
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
17 changes: 17 additions & 0 deletions lib/rufus/edo/cabinet/abstract.rb
Expand Up @@ -214,6 +214,23 @@ def initialize (path, params={})
self.default = params[:default]
@default_proc ||= params[:default_proc]
end

# This is a B+ Tree method only, puts a value for a key who has
# [potentially] multiple values.
#
def putdup (k, v)

@db.putdup(k, v)
end

# This is a B+ Tree method only, returns all the values for a given
# key.
#
def get4 (k)

@db.getlist(k)
end
alias :getdup :get4
end
end

2 changes: 1 addition & 1 deletion lib/rufus/tokyo/cabinet/abstract.rb
Expand Up @@ -562,7 +562,7 @@ def get4 (k)
#
def as_btree

raise(ArgumentError.new("cannot call B+ Tree function on #{@path}")) \
raise(NoMethodError.new("cannot call B+ Tree function on #{@path}")) \
if ! @path.match(/\.tcb$/)

lib.tcadbreveal(@db)
Expand Down
2 changes: 1 addition & 1 deletion spec/cabinet_btree_spec.rb
Expand Up @@ -37,7 +37,7 @@

@db = Rufus::Tokyo::Cabinet.new('tmp/cabinet_btree_spec.tch')

lambda { @db.putdup('a', 'a0') }.should.raise(ArgumentError)
lambda { @db.putdup('a', 'a0') }.should.raise(NoMethodError)
end
end

43 changes: 43 additions & 0 deletions spec/edo_cabinet_btree_spec.rb
@@ -0,0 +1,43 @@

#
# Specifying rufus-tokyo
#
# Fri Aug 28 08:58:37 JST 2009
#

require File.dirname(__FILE__) + '/spec_base'

require 'rufus/edo'

FileUtils.mkdir('tmp') rescue nil


describe 'Rufus::Edo::Cabinet .tcb' do

before do
@db = Rufus::Edo::Cabinet.new('tmp/edo_cabinet_btree_spec.tcb')
@db.clear
end
after do
@db.close
end

it 'should accept duplicate values' do

@db.putdup('a', 'a0')
@db.putdup('a', 'a1')

@db.getdup('a').should.equal([ 'a0', 'a1' ])
end
end

describe 'Rufus::Edo::Cabinet .tcb methods' do

it 'should fail on other structures' do

@db = Rufus::Edo::Cabinet.new('tmp/cabinet_btree_spec.tch')

lambda { @db.putdup('a', 'a0') }.should.raise(NoMethodError)
end
end

0 comments on commit 1ff4ed0

Please sign in to comment.