From 85e4fd8411c937f408884e25ab084404648166c8 Mon Sep 17 00:00:00 2001 From: jugyo Date: Thu, 14 Jan 2010 23:59:31 +0900 Subject: [PATCH] don't partition if the key includes '/'. --- lib/ykk.rb | 2 +- spec/ykk_spec.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/ykk.rb b/lib/ykk.rb index 0ad4c47..803030b 100644 --- a/lib/ykk.rb +++ b/lib/ykk.rb @@ -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 diff --git a/spec/ykk_spec.rb b/spec/ykk_spec.rb index 30a6447..940b171 100644 --- a/spec/ykk_spec.rb +++ b/spec/ykk_spec.rb @@ -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 @@ -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'}