ykk 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +4 -0
- data/VERSION +1 -1
- data/lib/ykk.rb +12 -6
- data/spec/ykk_spec.rb +22 -1
- metadata +2 -2
data/README.markdown
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0
|
data/lib/ykk.rb
CHANGED
@@ -3,8 +3,6 @@ require 'yaml'
|
|
3
3
|
require 'fileutils'
|
4
4
|
|
5
5
|
class YKK
|
6
|
-
@instance = self.new
|
7
|
-
|
8
6
|
def self.method_missing(method, *args, &block)
|
9
7
|
if @instance.respond_to?(method)
|
10
8
|
@instance.__send__(method, *args, &block)
|
@@ -17,10 +15,11 @@ class YKK
|
|
17
15
|
@instance.inspect
|
18
16
|
end
|
19
17
|
|
20
|
-
attr_accessor :dir
|
18
|
+
attr_accessor :dir, :partition_size
|
21
19
|
|
22
|
-
def initialize(
|
23
|
-
self.dir = dir
|
20
|
+
def initialize(options = {})
|
21
|
+
self.dir = options[:dir]
|
22
|
+
self.partition_size = options[:partition_size] || 0
|
24
23
|
end
|
25
24
|
|
26
25
|
def <<(value)
|
@@ -56,7 +55,12 @@ class YKK
|
|
56
55
|
key = key.to_s
|
57
56
|
raise ArgumentError, 'invalid key' unless key =~ /^[\w\/]+$/
|
58
57
|
raise "dir is not specified" unless dir
|
59
|
-
File.join(dir, key)
|
58
|
+
File.join(dir, *partition(key))
|
59
|
+
end
|
60
|
+
|
61
|
+
def partition(key)
|
62
|
+
return [key] if /\// =~ key || self.partition_size <= 0
|
63
|
+
key.scan(/.{1,#{partition_size}}/)
|
60
64
|
end
|
61
65
|
|
62
66
|
def key_gen(value)
|
@@ -69,4 +73,6 @@ class YKK
|
|
69
73
|
}
|
70
74
|
"YKK(#{pairs.join ', '})"
|
71
75
|
end
|
76
|
+
|
77
|
+
@instance = self.new
|
72
78
|
end
|
data/spec/ykk_spec.rb
CHANGED
@@ -8,6 +8,20 @@ describe YKK do
|
|
8
8
|
@tmpdir = Dir.tmpdir + '/ykk_test'
|
9
9
|
FileUtils.rm_rf(@tmpdir)
|
10
10
|
YKK.dir = @tmpdir
|
11
|
+
YKK.partition_size = 0
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'enable_partition = false' do
|
15
|
+
before do
|
16
|
+
YKK.partition_size = 2
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'generates file path' do
|
20
|
+
YKK.file_of('foo').should == @tmpdir + '/fo/o'
|
21
|
+
YKK.file_of('fooooo').should == @tmpdir + '/fo/oo/oo'
|
22
|
+
YKK.file_of('/fooooo').should == @tmpdir + '/fooooo' # 先頭に / を付けると fooooo というキーを使いつつディレクトリを分割しないという裏技が可能に!
|
23
|
+
YKK.file_of('foo/bar').should == @tmpdir + '/foo/bar' # / を使うと任意の箇所でディレクトリ階層を分けることが可能に!
|
24
|
+
end
|
11
25
|
end
|
12
26
|
|
13
27
|
it 'generates file path' do
|
@@ -24,6 +38,13 @@ describe YKK do
|
|
24
38
|
File.exists?(YKK.file_of('a/b')).should be_true
|
25
39
|
end
|
26
40
|
|
41
|
+
it 'should raise error when bump filename and dirname' do
|
42
|
+
YKK['foo'] = 'foo'
|
43
|
+
lambda {
|
44
|
+
YKK['foo/bar'] = 'foo bar'
|
45
|
+
}.should raise_error(Errno::ENOTDIR)
|
46
|
+
end
|
47
|
+
|
27
48
|
it 'should store data with "<<"' do
|
28
49
|
key = YKK << {:a => 'b', :c => 'd'}
|
29
50
|
YKK[key].should == {:a => 'b', :c => 'd'}
|
@@ -89,7 +110,7 @@ describe YKK do
|
|
89
110
|
before do
|
90
111
|
@tmpdir_for_foo = Dir.tmpdir + '/ykk_test_foo'
|
91
112
|
FileUtils.rm_rf(@tmpdir_for_foo)
|
92
|
-
@ykk = YKK.new(@tmpdir_for_foo)
|
113
|
+
@ykk = YKK.new(:dir => @tmpdir_for_foo)
|
93
114
|
end
|
94
115
|
|
95
116
|
it 'generates file path' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ykk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jugyo
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-15 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|