tagen 0.2.1 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,4 @@
1
+ require "rmagic"
1
2
  =begin
2
3
  * **gem**: rmagic
3
4
  =end
@@ -1,3 +1,4 @@
1
+ require "ncurses"
1
2
  =begin
2
3
 
3
4
  Ncurses
@@ -1,3 +1,4 @@
1
+ require "pathname"
1
2
  =begin
2
3
  Additional Methods List
3
4
  -----------------------
@@ -1,3 +1,4 @@
1
+ require "poppler"
1
2
  =begin
2
3
  * **Install**: Ruby-Gnome
3
4
  =end
@@ -1,3 +1,5 @@
1
+ require "socket"
2
+
1
3
  class Socket
2
4
  class <<self
3
5
  # pack human-readable address to Socket address
@@ -1,3 +1,5 @@
1
+ require "tree"
2
+
1
3
  =begin
2
4
  * **Install**: gem(rubytree)
3
5
  =end
@@ -1 +1,2 @@
1
+ require "xmpp4r"
1
2
  require_relative "xmpp4r/roster"
@@ -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
@@ -1 +1,15 @@
1
1
  require "tagen/core"
2
+
3
+ class Pa
4
+ class << self
5
+ public :_copy, :_move
6
+ end
7
+ end
8
+
9
+ class Dir
10
+ class << self
11
+ def empty? path
12
+ Dir.entries(path).sort == %w(. ..)
13
+ end
14
+ end
15
+ end
@@ -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
- $tmpdir = Dir.mktmpdir
8
- Dir.chdir($tmpdir)
7
+ @curdir = Dir.pwd
8
+ @tmpdir = Dir.mktmpdir
9
+ Dir.chdir(@tmpdir)
9
10
  end
10
11
 
11
12
  after(:all) do
12
- FileUtils.rm_r $tmpdir
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
- @_copy.call Pa('a'), Pa('b')
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
- @_copy.call Pa('dir'), Pa('dirc')
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
- @_copy.call Pa('symfile'), Pa('symfilea')
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
- @_copy.call Pa('symfile'), Pa('folsymlink'), folsymlink:true
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
- @_move.call Pa("a"), Pa("dir/a"), {}
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{@_move.call Pa("a"), Pa("dir/b"), {}}.should raise_error Errno::EEXIST
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
- @_move.call Pa("a"), Pa("dir/b"), overwrite:true
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
- $tmpdir = Dir.mktmpdir
8
- Dir.chdir($tmpdir)
7
+ @curdir = Dir.pwd
8
+ @tmpdir = Dir.mktmpdir
9
+ Dir.chdir(@tmpdir)
9
10
  end
10
11
 
11
12
  after(:all) do
12
- FileUtils.rm_r $tmpdir
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
- Pa.each.with_object([]){|pa,m|m<<pa.b}.sort.should == %w(.fa dira fa fa~)
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,7 @@
1
+ require "spec_helper"
2
+
3
+ describe Pa do
4
+ describe "#chmod" do
5
+ #Pa("path_doesn't_exists").chmod(777)
6
+ end
7
+ 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