ykk 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/ykk.rb +4 -7
- data/spec/ykk_spec.rb +4 -4
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.1.0
|
data/lib/ykk.rb
CHANGED
@@ -41,7 +41,8 @@ class YKK
|
|
41
41
|
|
42
42
|
def []=(key, value)
|
43
43
|
path = file_of(key)
|
44
|
-
|
44
|
+
dirname = File.dirname(path)
|
45
|
+
FileUtils.mkdir_p(dirname) unless File.exists?(dirname)
|
45
46
|
File.open(path, 'wb') { |f| f << value.to_yaml }
|
46
47
|
end
|
47
48
|
|
@@ -53,17 +54,13 @@ class YKK
|
|
53
54
|
|
54
55
|
def file_of(key)
|
55
56
|
key = key.to_s
|
56
|
-
raise ArgumentError, 'invalid key' unless key =~ /^[\w]+$/
|
57
|
+
raise ArgumentError, 'invalid key' unless key =~ /^[\w\/]+$/
|
57
58
|
raise "dir is not specified" unless dir
|
58
59
|
File.join(dir, key)
|
59
60
|
end
|
60
61
|
|
61
62
|
def key_gen(value)
|
62
|
-
Digest::SHA1.hexdigest(value.
|
63
|
-
end
|
64
|
-
|
65
|
-
def keys
|
66
|
-
Dir.glob(dir + '/*').map {|f| File.basename(f) }
|
63
|
+
Digest::SHA1.hexdigest(value.to_yaml)
|
67
64
|
end
|
68
65
|
|
69
66
|
def inspect
|
data/spec/ykk_spec.rb
CHANGED
@@ -12,15 +12,16 @@ describe YKK do
|
|
12
12
|
|
13
13
|
it 'generates file path' do
|
14
14
|
YKK.file_of('foo').should == @tmpdir + '/foo'
|
15
|
+
YKK.file_of('foo/bar').should == @tmpdir + '/foo/bar'
|
15
16
|
end
|
16
17
|
|
17
18
|
it 'stores data' do
|
18
19
|
YKK['foo'] = {:a => 'b', :c => 'd'}
|
19
20
|
YKK['foo'].should == {:a => 'b', :c => 'd'}
|
20
21
|
File.exists?(YKK.file_of('foo')).should be_true
|
21
|
-
YKK['
|
22
|
-
YKK
|
23
|
-
|
22
|
+
YKK['a/b'] = {:e => 'f', :g => 'h'}
|
23
|
+
YKK['a/b'].should == {:e => 'f', :g => 'h'}
|
24
|
+
File.exists?(YKK.file_of('a/b')).should be_true
|
24
25
|
end
|
25
26
|
|
26
27
|
it 'should store data with "<<"' do
|
@@ -70,7 +71,6 @@ describe YKK do
|
|
70
71
|
it 'raises ArgumentError' do
|
71
72
|
lambda { YKK['.'] }.should raise_error(ArgumentError)
|
72
73
|
lambda { YKK['../'] }.should raise_error(ArgumentError)
|
73
|
-
lambda { YKK['/'] }.should raise_error(ArgumentError)
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
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.1.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-09 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|