Skip to content

Commit

Permalink
don't partition if the key includes '/'.
Browse files Browse the repository at this point in the history
  • Loading branch information
jugyo committed Jan 14, 2010
1 parent 08f9f72 commit 85e4fd8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ykk.rb
Expand Up @@ -59,7 +59,7 @@ def file_of(key)
end

def partition(key)
return [key] unless self.partition_size > 0
return [key] if /\// =~ key || self.partition_size <= 0
key.scan(/.{1,#{partition_size}}/)
end

Expand Down
9 changes: 9 additions & 0 deletions spec/ykk_spec.rb
Expand Up @@ -19,6 +19,8 @@
it 'generates file path' do
YKK.file_of('foo').should == @tmpdir + '/fo/o'
YKK.file_of('fooooo').should == @tmpdir + '/fo/oo/oo'
YKK.file_of('/fooooo').should == @tmpdir + '/fooooo' # 先頭に / を付けると fooooo というキーを使いつつディレクトリを分割しないという裏技が可能に!
YKK.file_of('foo/bar').should == @tmpdir + '/foo/bar' # / を使うと任意の箇所でディレクトリ階層を分けることが可能に!
end
end

Expand All @@ -36,6 +38,13 @@
File.exists?(YKK.file_of('a/b')).should be_true
end

it 'should raise error when bump filename and dirname' do
YKK['foo'] = 'foo'
lambda {
YKK['foo/bar'] = 'foo bar'
}.should raise_error(Errno::ENOTDIR)
end

it 'should store data with "<<"' do
key = YKK << {:a => 'b', :c => 'd'}
YKK[key].should == {:a => 'b', :c => 'd'}
Expand Down

0 comments on commit 85e4fd8

Please sign in to comment.