tagen 0.2.1 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +36 -1
- data/Rakefile +8 -1
- data/TODO +1 -0
- data/lib/tagen/audioinfo.rb +1 -0
- data/lib/tagen/cairo.rb +2 -0
- data/lib/tagen/core.rb +2 -0
- data/lib/tagen/core/array.rb +58 -0
- data/lib/tagen/core/enumerable.rb +20 -0
- data/lib/tagen/core/enumerator.rb +29 -0
- data/lib/tagen/core/module.rb +5 -4
- data/lib/tagen/core/pa.rb +53 -75
- data/lib/tagen/core/pa/cmd.rb +59 -52
- data/lib/tagen/core/pa/dir.rb +41 -20
- data/lib/tagen/core/pa/path.rb +132 -31
- data/lib/tagen/core/pa/state.rb +17 -6
- data/lib/tagen/core/string/pyformat.rb +2 -2
- data/lib/tagen/erb.rb +35 -0
- data/lib/tagen/magick.rb +1 -0
- data/lib/tagen/ncurses.rb +1 -0
- data/lib/tagen/pathname.rb +1 -0
- data/lib/tagen/poppler.rb +1 -0
- data/lib/tagen/socket.rb +2 -0
- data/lib/tagen/tree.rb +2 -0
- data/lib/tagen/xmpp4r.rb +1 -0
- data/lib/tagen/yaml.rb +36 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/tagen/core/array_spec.rb +37 -0
- data/spec/tagen/core/enumerator_spec.rb +21 -0
- data/spec/tagen/core/pa/cmd_spec.rb +17 -14
- data/spec/tagen/core/pa/dir_spec.rb +20 -5
- data/spec/tagen/core/pa/path_spec.rb +117 -0
- data/spec/tagen/core/pa/state_spec.rb +7 -0
- data/spec/tagen/erb_spec.rb +19 -0
- data/spec/tagen/yaml_spec.rb +32 -0
- data/version.rb +1 -1
- metadata +13 -2
data/lib/tagen/magick.rb
CHANGED
data/lib/tagen/ncurses.rb
CHANGED
data/lib/tagen/pathname.rb
CHANGED
data/lib/tagen/poppler.rb
CHANGED
data/lib/tagen/socket.rb
CHANGED
data/lib/tagen/tree.rb
CHANGED
data/lib/tagen/xmpp4r.rb
CHANGED
data/lib/tagen/yaml.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require "yaml"
|
2
|
+
|
3
|
+
=begin
|
4
|
+
YAML.load(Pa('/tmp/a'))
|
5
|
+
YAML.dump("x", Pa('/tmp/a'))
|
6
|
+
=end
|
7
|
+
module YAML
|
8
|
+
class << self
|
9
|
+
alias original_load load
|
10
|
+
alias original_dump dump
|
11
|
+
|
12
|
+
# add #path support
|
13
|
+
# @param [String,IO,#path] path
|
14
|
+
def load path
|
15
|
+
if path.respond_to?(:path)
|
16
|
+
path = path.path
|
17
|
+
open(path){|f| original_load(f)}
|
18
|
+
|
19
|
+
else
|
20
|
+
original_load path
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# add String, #path support
|
25
|
+
# @param [String,IO,#path] path
|
26
|
+
def dump obj, path
|
27
|
+
if path.respond_to?(:path)
|
28
|
+
path = path.path
|
29
|
+
open(path, "w+"){|f| original_dump(obj, f)}
|
30
|
+
else
|
31
|
+
original_dump obj, path
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,37 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Array do
|
4
|
+
describe "#first!" do
|
5
|
+
it "runs ok" do
|
6
|
+
a = [0, 1, 2]
|
7
|
+
a.first!(2).should == [0, 1]
|
8
|
+
a.should == [2]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#last!" do
|
13
|
+
it "runs ok" do
|
14
|
+
a = [0, 1, 2]
|
15
|
+
a.last!(2).should == [1, 2]
|
16
|
+
a.should == [0]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#find!" do
|
21
|
+
it "runs ok" do
|
22
|
+
a = [0, 1, 2]
|
23
|
+
a.find!{|v| v==1}.should == 1
|
24
|
+
a.should == [0,2]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#find_all!" do
|
29
|
+
it "runs ok" do
|
30
|
+
a = [0, 1, 2]
|
31
|
+
a.find_all!{|v| v==0 or v ==2}.should == [0,2]
|
32
|
+
a.should == [1]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Enumerator do
|
4
|
+
describe "#with_iobject" do
|
5
|
+
|
6
|
+
it "support mem_obj" do
|
7
|
+
ret = [1,2].each.with_iobject [] do |v,i, m|
|
8
|
+
m << v
|
9
|
+
end
|
10
|
+
ret.should == [1,2]
|
11
|
+
end
|
12
|
+
|
13
|
+
it "support offset" do
|
14
|
+
ret = [1,2].each.with_iobject 2, [] do |v,i, m|
|
15
|
+
m << i
|
16
|
+
end
|
17
|
+
ret.should == [2,3]
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -4,12 +4,14 @@ require "tmpdir"
|
|
4
4
|
|
5
5
|
describe Pa do
|
6
6
|
before :all do
|
7
|
-
|
8
|
-
Dir.
|
7
|
+
@curdir = Dir.pwd
|
8
|
+
@tmpdir = Dir.mktmpdir
|
9
|
+
Dir.chdir(@tmpdir)
|
9
10
|
end
|
10
11
|
|
11
12
|
after(:all) do
|
12
|
-
|
13
|
+
Dir.chdir(@curdir)
|
14
|
+
FileUtils.rm_r @tmpdir
|
13
15
|
end
|
14
16
|
|
15
17
|
describe "#_rmdir" do
|
@@ -90,7 +92,6 @@ describe Pa do
|
|
90
92
|
end
|
91
93
|
end
|
92
94
|
|
93
|
-
|
94
95
|
describe "#_copy" do
|
95
96
|
# a symfile
|
96
97
|
# ab
|
@@ -103,7 +104,6 @@ describe Pa do
|
|
103
104
|
# b # tag
|
104
105
|
# dir/
|
105
106
|
before :all do
|
106
|
-
@_copy = Pa.method(:_copy)
|
107
107
|
FileUtils.mkdir_p(%w(dir/dira destdir/dir))
|
108
108
|
FileUtils.touch(%w(a ab ac dir/b dir/dira/c destdir/dir/b))
|
109
109
|
File.symlink("a", "symfile")
|
@@ -112,24 +112,24 @@ describe Pa do
|
|
112
112
|
end
|
113
113
|
|
114
114
|
it "_copy file" do
|
115
|
-
|
115
|
+
Pa._copy 'a', 'b'
|
116
116
|
File.exists?('b').should be_true
|
117
117
|
end
|
118
118
|
|
119
119
|
it "_copy directory" do
|
120
|
-
|
120
|
+
Pa._copy 'dir', 'dirc'
|
121
121
|
Dir.entries('dirc').should == Dir.entries('dir')
|
122
122
|
end
|
123
123
|
|
124
124
|
context "with :symlink" do
|
125
125
|
|
126
126
|
it "_copy" do
|
127
|
-
|
127
|
+
Pa._copy 'symfile', 'symfilea'
|
128
128
|
File.symlink?('symfilea').should be_true
|
129
129
|
end
|
130
130
|
|
131
131
|
it "_copy with :folsymlink" do
|
132
|
-
|
132
|
+
Pa._copy 'symfile', 'folsymlink', folsymlink:true
|
133
133
|
File.symlink?('folsymlink').should be_false
|
134
134
|
File.file?('folsymlink').should be_true
|
135
135
|
end
|
@@ -163,6 +163,11 @@ describe Pa do
|
|
163
163
|
end
|
164
164
|
end
|
165
165
|
|
166
|
+
it "_copy with :normal" do
|
167
|
+
Pa._copy 'dir', 'dir_normal', special: true
|
168
|
+
Dir.empty?('dir_normal').should be_true
|
169
|
+
end
|
170
|
+
|
166
171
|
end
|
167
172
|
|
168
173
|
describe "#cp" do
|
@@ -192,7 +197,6 @@ describe Pa do
|
|
192
197
|
# a
|
193
198
|
# dir/ b
|
194
199
|
before :each do
|
195
|
-
@_move = Pa.method(:_move)
|
196
200
|
FileUtils.mkdir_p(%w(dir))
|
197
201
|
FileUtils.touch(%w(a dir/b))
|
198
202
|
end
|
@@ -202,19 +206,19 @@ describe Pa do
|
|
202
206
|
|
203
207
|
it "mv a dir/a" do
|
204
208
|
ino = File.stat('a').ino
|
205
|
-
|
209
|
+
Pa._move "a", "dir/a", {}
|
206
210
|
File.stat('dir/a').ino.should == ino
|
207
211
|
File.exists?("a").should be_false
|
208
212
|
end
|
209
213
|
|
210
214
|
context "with :overwrite" do
|
211
215
|
it "mv a dir/b" do
|
212
|
-
lambda{
|
216
|
+
lambda{Pa._move "a", "dir/b", {}}.should raise_error Errno::EEXIST
|
213
217
|
end
|
214
218
|
|
215
219
|
it "mv a dir/b :overwrite" do
|
216
220
|
ino = File.stat('a').ino
|
217
|
-
|
221
|
+
Pa._move "a", "dir/b", overwrite:true
|
218
222
|
File.stat("dir/b").ino.should == ino
|
219
223
|
end
|
220
224
|
end
|
@@ -224,7 +228,6 @@ describe Pa do
|
|
224
228
|
# a b c
|
225
229
|
# dir/ aa
|
226
230
|
before :each do
|
227
|
-
@_move = Pa.method(:_move)
|
228
231
|
FileUtils.mkdir_p(%w(dir))
|
229
232
|
FileUtils.touch(%w(a b c dir/aa))
|
230
233
|
end
|
@@ -4,12 +4,14 @@ require "tmpdir"
|
|
4
4
|
|
5
5
|
describe Pa do
|
6
6
|
before :all do
|
7
|
-
|
8
|
-
Dir.
|
7
|
+
@curdir = Dir.pwd
|
8
|
+
@tmpdir = Dir.mktmpdir
|
9
|
+
Dir.chdir(@tmpdir)
|
9
10
|
end
|
10
11
|
|
11
12
|
after(:all) do
|
12
|
-
|
13
|
+
Dir.chdir(@curdir)
|
14
|
+
FileUtils.rm_r @tmpdir
|
13
15
|
end
|
14
16
|
|
15
17
|
describe "#glob" do
|
@@ -40,13 +42,26 @@ describe Pa do
|
|
40
42
|
FileUtils.touch(%w(fa .fa fa~ dira/dirb/b))
|
41
43
|
end
|
42
44
|
|
45
|
+
it "runs on" do
|
46
|
+
ret = []
|
47
|
+
Pa.each{|pa| ret << pa.b}
|
48
|
+
ret.sort.should == %w(.fa dira fa fa~)
|
49
|
+
end
|
50
|
+
|
43
51
|
it "return a Enumerator when call without block" do
|
44
52
|
Pa.each.should be_an_instance_of Enumerator
|
45
|
-
|
53
|
+
end
|
54
|
+
|
55
|
+
it "raise Errno::ENOENT if path doesn't exists" do
|
56
|
+
lambda { Pa.each("path_doesn't_exits"){} }.should raise_error(Errno::ENOENT)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "raise Errno::ENOTDIDR if path isn't a directory" do
|
60
|
+
lambda { Pa.each("fa"){} }.should raise_error(Errno::ENOTDIR)
|
46
61
|
end
|
47
62
|
|
48
63
|
it "each(.) return 'foo' not '.foo'" do
|
49
|
-
Pa.each.with_object([]){|pa,m|m<<pa.p}.sort.should == %w(.fa dira fa fa~)
|
64
|
+
Pa.each.with_object([]){|pa,m| m<<pa.p}.sort.should == %w(.fa dira fa fa~)
|
50
65
|
end
|
51
66
|
|
52
67
|
it "each(nodot: true) -> list all files except dot file" do
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Pa do
|
4
|
+
describe ".shorten" do
|
5
|
+
it "short /home/usr/file into ~/file" do
|
6
|
+
ENV["HOME"] = "/home/foo"
|
7
|
+
Pa.shorten("/home/foo/file").should == "~/file"
|
8
|
+
end
|
9
|
+
|
10
|
+
it "not short /home/other-user/file" do
|
11
|
+
ENV["HOME"] = "/home/foo"
|
12
|
+
Pa.shorten("/home/bar/file").should == "/home/bar/file"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "NAME_EXT_PAT" do
|
17
|
+
it "matchs `foo.bar'" do
|
18
|
+
"foo.bar".match(Pa::NAME_EXT_PAT).captures.should == %w(foo bar)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "matchs `foo'" do
|
22
|
+
"foo".match(Pa::NAME_EXT_PAT).captures.should == ["foo", nil]
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "basename" do
|
28
|
+
it "get a basename of a path" do
|
29
|
+
Pa.basename("/home/foo").should == "foo"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "get name, ext with :ext => true" do
|
33
|
+
Pa.basename("/home/foo.bar", ext: true).should == ["foo", "bar"]
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '.parent' do
|
39
|
+
before :each do
|
40
|
+
@path = "/home/foo/a.txt"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "return parent path" do
|
44
|
+
Pa.parent(@path).should == "/home/foo"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "return parent upto 2 level path" do
|
48
|
+
Pa.parent(@path, 2).should == "/home"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "#==" do
|
53
|
+
it "runs ok" do
|
54
|
+
(Pa('/home') == Pa('/home')).should be_true
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#+" do
|
59
|
+
it "runs ok" do
|
60
|
+
(Pa('/home')+'~').should == Pa('/home~')
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "#sub" do
|
65
|
+
it "runs ok" do
|
66
|
+
Pa('/home/foo').sub(/o/,'').should == Pa('/hme/foo')
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "#sub!" do
|
71
|
+
it "runs ok" do
|
72
|
+
pa = Pa('/home/foo')
|
73
|
+
pa.sub!(/o/,'')
|
74
|
+
pa.should == Pa('/hme/foo')
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "#gsub" do
|
79
|
+
it "runs ok" do
|
80
|
+
Pa('/home/foo').gsub(/o/,'').should == Pa('/hme/f')
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "#gsub!" do
|
85
|
+
it "runs ok" do
|
86
|
+
pa = Pa('/home/foo')
|
87
|
+
pa.gsub!(/o/,'')
|
88
|
+
pa.should == Pa('/hme/f')
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "#match" do
|
93
|
+
it "runs ok" do
|
94
|
+
Pa('/home/foo').match(/foo/)[0].should == 'foo'
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "#start_with?" do
|
99
|
+
it "runs ok" do
|
100
|
+
Pa('/home/foo').start_with?('/home').should be_true
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "#end_with?" do
|
105
|
+
it "runs ok" do
|
106
|
+
Pa('/home/foo').end_with?('foo').should be_true
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "#=~" do
|
111
|
+
it "runs ok" do
|
112
|
+
(Pa('/home/foo') =~ /foo/).should be_true
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "tagen/erb"
|
3
|
+
|
4
|
+
describe ERB do
|
5
|
+
describe "#result" do
|
6
|
+
before :all do
|
7
|
+
@erb = ERB.new("<%=a%>")
|
8
|
+
end
|
9
|
+
|
10
|
+
it "runs ok" do
|
11
|
+
a = 1
|
12
|
+
@erb.result(binding).should == "1"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "runs ok with local " do
|
16
|
+
@erb.result(nil, a: 2).should == "2"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|