id2path 0.1.0 → 0.1.1
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/id2path.gemspec +1 -1
- data/lib/id2path.rb +3 -2
- data/test/test_id2path.rb +19 -3
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/id2path.gemspec
CHANGED
data/lib/id2path.rb
CHANGED
@@ -2,9 +2,10 @@ module Id2path
|
|
2
2
|
|
3
3
|
def create_path root
|
4
4
|
dir1, dir2, file = self.id.to_s.rjust(9, '0').scan(/\d{3}/)
|
5
|
-
Dir.mkdir(
|
6
|
-
Dir.mkdir(
|
5
|
+
Dir.mkdir(File.join(root, dir1)) unless File.directory?(File.join(root, dir1))
|
6
|
+
Dir.mkdir(File.join(root, dir1, dir2)) unless File.directory?(File.join(root, dir1, dir2))
|
7
7
|
File.join(root, dir1, dir2, file)
|
8
8
|
end
|
9
9
|
|
10
|
+
|
10
11
|
end
|
data/test/test_id2path.rb
CHANGED
@@ -1,7 +1,23 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class TestId2path < Test::Unit::TestCase
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
|
5
|
+
context 'a object with a id attribute' do
|
6
|
+
setup do
|
7
|
+
C = Class.new {
|
8
|
+
include Id2path
|
9
|
+
|
10
|
+
def id
|
11
|
+
@id = '123456'
|
12
|
+
end
|
13
|
+
}
|
14
|
+
@object_with_id = C.new
|
15
|
+
end
|
16
|
+
|
17
|
+
should "create dir and file for id" do
|
18
|
+
path = @object_with_id.create_path(File.expand_path('~'))
|
19
|
+
assert_equal File.expand_path(path, '~'), path
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
7
23
|
end
|
metadata
CHANGED