tagen 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/tagen/core.rb CHANGED
@@ -32,7 +32,6 @@ require "pd"
32
32
  core/io
33
33
  core/process
34
34
 
35
- core/pa
36
35
  core/open_option
37
36
  ).each {|n| require_relative n }
38
37
 
data/lib/tagen/yaml.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require "yaml"
2
2
 
3
3
  =begin
4
+ support #respond_to?(:path). e.g. Pa
5
+
4
6
  YAML.load(Pa('/tmp/a'))
5
7
  YAML.dump("x", Pa('/tmp/a'))
6
8
  =end
data/spec/spec_helper.rb CHANGED
@@ -1,10 +1,5 @@
1
1
  require "tagen/core"
2
2
 
3
- class Pa
4
- class << self
5
- public :_copy, :_move
6
- end
7
- end
8
3
 
9
4
  class Dir
10
5
  class << self
data/version.rb CHANGED
@@ -2,7 +2,7 @@ module Tagen
2
2
  module VERSION
3
3
  MAJOR = 1
4
4
  MINOR = 0
5
- PATCH = 1
5
+ PATCH = 2
6
6
 
7
7
  IS = [MAJOR, MINOR, PATCH].join(".")
8
8
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 1
9
- version: 1.0.1
8
+ - 2
9
+ version: 1.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Guten
@@ -107,14 +107,9 @@ files:
107
107
  - spec/tagen/core/enumerator_spec.rb
108
108
  - spec/tagen/core/module_spec.rb
109
109
  - spec/tagen/core/open_option_spec.rb
110
- - spec/tagen/core/pa/cmd_spec.rb
111
- - spec/tagen/core/pa/dir_spec.rb
112
- - spec/tagen/core/pa/path_spec.rb
113
- - spec/tagen/core/pa/state_spec.rb
114
110
  - spec/tagen/core/string/pyformat_spec.rb
115
111
  - spec/tagen/core/symbol_spec.rb
116
112
  - spec/tagen/erb_spec.rb
117
- - spec/tagen/yaml_spec.rb
118
113
  - tagen.gemspec
119
114
  - tagen.watchr
120
115
  - version.rb
@@ -1,269 +0,0 @@
1
- require "spec_helper"
2
- require "fileutils"
3
- require "tmpdir"
4
-
5
- describe Pa do
6
- before :all do
7
- @curdir = Dir.pwd
8
- @tmpdir = Dir.mktmpdir
9
- Dir.chdir(@tmpdir)
10
- end
11
-
12
- after(:all) do
13
- Dir.chdir(@curdir)
14
- FileUtils.rm_r @tmpdir
15
- end
16
-
17
- describe "#_rmdir" do
18
- # dir/
19
- # a
20
- # dira/
21
- # aa
22
- before(:all) do
23
- @_rmdir = Pa.method(:_rmdir)
24
- FileUtils.mkdir_p(%w(dir/dira))
25
- FileUtils.touch(%w(dir/a dir/dira/aa))
26
- end
27
-
28
- it "remove directory" do
29
- @_rmdir.call Pa("dir")
30
- File.exists?("dir").should be_false
31
- end
32
- end
33
-
34
- # rm family
35
- describe "" do
36
- # a
37
- # dir/
38
- # dira/
39
- # a
40
- before :each do
41
- FileUtils.mkdir_p(%w(dir/dira))
42
- FileUtils.touch(%w(a dir/a))
43
- end
44
-
45
- describe "#rm" do
46
- it "remove file" do
47
- Pa.rm "a"
48
- File.exists?("a").should be_false
49
- lambda{Pa.rm("dir")}.should raise_error(Errno::EISDIR)
50
- end
51
- end
52
-
53
- describe "#rm_f" do
54
- it "remove file force" do
55
- lambda{Pa.rm_f("dir")}.should_not raise_error(Errno::EISDIR)
56
- end
57
- end
58
-
59
- describe "#rmdir" do
60
- it "remove directory" do
61
- Pa.rmdir "dir"
62
- File.exists?("dir").should be_false
63
- lambda{Pa.rmdir("a")}.should raise_error(Errno::ENOTDIR)
64
- end
65
- end
66
-
67
- describe "#rmdir_f" do
68
- it "remove directory force" do
69
- lambda{Pa.rmdir_r("a")}.should_not raise_error(Errno::ENOTDIR)
70
- end
71
- end
72
-
73
- describe "#rm_r" do
74
- it "remove both file and directory" do
75
- Pa.rm "a"
76
- File.exists?("a").should be_false
77
- Pa.rm_r "dir"
78
- File.exists?("dir").should be_false
79
- end
80
- end
81
-
82
-
83
-
84
- describe "#rm_if" do
85
- it "remove if condition" do
86
- Pa.rm_if "." do |pa|
87
- next if pa.p=="a"
88
- yield if pa.b=="a"
89
- end
90
-
91
- File.exists?("a").should be_true
92
- File.exists?("dir/dira/a").should be_false
93
- end
94
- end
95
-
96
- end
97
-
98
- describe "#mkdir" do
99
- after :each do
100
- FileUtils.rm_r Dir["*"]-%w(. ..)
101
- end
102
-
103
- it "mkdir" do
104
- Pa.mkdir("guten/tag")
105
- File.exists?("guten/tag").should be_true
106
- end
107
- end
108
-
109
- describe "#_copy" do
110
- # a symfile
111
- # ab
112
- # ac
113
- # dir/
114
- # b # guten
115
- # dira/
116
- # c
117
- # destdir/
118
- # b # tag
119
- # dir/
120
- before :all do
121
- FileUtils.mkdir_p(%w(dir/dira destdir/dir))
122
- FileUtils.touch(%w(a ab ac dir/b dir/dira/c destdir/dir/b))
123
- File.symlink("a", "symfile")
124
- open("dir/b", "w"){|f|f.write "guten"}
125
- open("destdir/dir/b", "w"){|f|f.write "tag"}
126
- end
127
-
128
- it "_copy file" do
129
- Pa._copy 'a', 'b'
130
- File.exists?('b').should be_true
131
- end
132
-
133
- it "_copy directory" do
134
- Pa._copy 'dir', 'dirc'
135
- Dir.entries('dirc').should == Dir.entries('dir')
136
- end
137
-
138
- context "with :symlink" do
139
-
140
- it "_copy" do
141
- Pa._copy 'symfile', 'symfilea'
142
- File.symlink?('symfilea').should be_true
143
- end
144
-
145
- it "_copy with :folsymlink" do
146
- Pa._copy 'symfile', 'folsymlink', folsymlink:true
147
- File.symlink?('folsymlink').should be_false
148
- File.file?('folsymlink').should be_true
149
- end
150
-
151
- end
152
-
153
- context "with :mkdir" do
154
- it "_copy" do
155
- lambda{Pa.cp "a", "destdir/mkdir/dir"}.should raise_error(Errno::ENOENT)
156
- end
157
-
158
- it "_copy with :mkdir" do
159
- lambda{Pa.cp "a", "destdir/mkdir/dir", mkdir:true}.should_not raise_error(Errno::ENOENT)
160
- File.exists?("destdir/mkdir/dir/a").should be_true
161
- end
162
-
163
- it "_copy with :mkdir" do
164
- lambda{Pa.cp "a", "destdir/mkdira", mkdir:true}.should_not raise_error(Errno::ENOENT)
165
- File.exists?("destdir/mkdira/a").should be_true
166
- end
167
- end
168
-
169
- context "with :force" do
170
- it "_copy" do
171
- File.open("destdir/overwrite","w"){|f|f.write("")}
172
- lambda{Pa.cp "a", "destdir/overwrite"}.should raise_error(Errno::EEXIST)
173
- end
174
-
175
- it "_copy with :force" do
176
- lambda{Pa.cp "a", "destdir/overwrite", force:true}.should_not raise_error(Errno::EEXIST)
177
- end
178
- end
179
-
180
- it "_copy with :normal" do
181
- Pa._copy 'dir', 'dir_normal', special: true
182
- Dir.empty?('dir_normal').should be_true
183
- end
184
-
185
- end
186
-
187
- describe "#cp" do
188
- it "cp file destdir/file" do
189
- Pa.cp "a", "destdir/aa"
190
- File.exists?("destdir/aa").should be_true
191
- end
192
-
193
- it "cp file destdir/" do
194
- Pa.cp "a", "destdir"
195
- File.exists?("destdir/a").should be_true
196
- end
197
-
198
- it "cp file1 file2 .. dest_file" do
199
- lambda{Pa.cp(%w(a ab), "ac")}.should raise_error(Errno::ENOTDIR)
200
- end
201
-
202
- it "cp file1 file2 .. dird/" do
203
- Dir.mkdir 'dird'
204
- Pa.cp %w(a ab), "dird"
205
- File.exists?("dird/a").should be_true
206
- File.exists?("dird/ab").should be_true
207
- end
208
- end
209
-
210
- describe "#_move" do
211
- # a
212
- # dir/ b
213
- before :each do
214
- FileUtils.mkdir_p(%w(dir))
215
- FileUtils.touch(%w(a dir/b))
216
- end
217
- after :each do
218
- FileUtils.rm_r Dir["*"]-%w(. ..)
219
- end
220
-
221
- it "mv a dir/a" do
222
- ino = File.stat('a').ino
223
- Pa._move "a", "dir/a", {}
224
- File.stat('dir/a').ino.should == ino
225
- File.exists?("a").should be_false
226
- end
227
-
228
- context "with :force" do
229
- it "mv a dir/b" do
230
- lambda{Pa._move "a", "dir/b", {}}.should raise_error Errno::EEXIST
231
- end
232
-
233
- it "mv a dir/b :force" do
234
- ino = File.stat('a').ino
235
- Pa._move "a", "dir/b", force:true
236
- File.stat("dir/b").ino.should == ino
237
- end
238
- end
239
-
240
- end
241
-
242
- describe "#mv" do
243
- # a b c
244
- # dir/ aa
245
- before :each do
246
- FileUtils.mkdir_p(%w(dir))
247
- FileUtils.touch(%w(a b c dir/aa))
248
- end
249
- after :each do
250
- FileUtils.rm_r Dir["*"]-%w(. ..)
251
- end
252
-
253
- it "mv a dir/" do
254
- Pa.mv "a", "dir"
255
- File.exists?("dir/a").should be_true
256
- end
257
-
258
- it "mv a b .. file" do
259
- lambda{Pa.mv(%w(a b), "c")}.should raise_error(Errno::ENOTDIR)
260
- end
261
-
262
- it "mv file1 file2 .. dir/" do
263
- Pa.mv %w(a b), "dir"
264
- File.exists?("dir/a").should be_true
265
- File.exists?("dir/b").should be_true
266
- end
267
- end
268
-
269
- end
@@ -1,78 +0,0 @@
1
- require "spec_helper"
2
- require "fileutils"
3
- require "tmpdir"
4
-
5
- describe Pa do
6
- before :all do
7
- @curdir = Dir.pwd
8
- @tmpdir = Dir.mktmpdir
9
- Dir.chdir(@tmpdir)
10
- end
11
-
12
- after(:all) do
13
- Dir.chdir(@curdir)
14
- FileUtils.rm_r @tmpdir
15
- end
16
-
17
- describe "#glob" do
18
- before(:all) do
19
- FileUtils.touch(%w(fa .fa))
20
- end
21
-
22
- context "call without any option" do
23
- it "returns 1 items" do
24
- Pa.glob("*").should have(1).items
25
- end
26
- end
27
-
28
- context "call with :dotmatch option" do
29
- it "returns 2 items" do
30
- Pa.glob("*", dotmatch: true).should have(2).items
31
- end
32
- end
33
- end
34
-
35
- describe "#each" do
36
- # fa .fa fa~
37
- # dira/
38
- # dirb/
39
- # b
40
- before(:all) do
41
- FileUtils.mkdir_p(["dira/dirb"])
42
- FileUtils.touch(%w(fa .fa fa~ dira/dirb/b))
43
- end
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
-
51
- it "return a Enumerator when call without block" do
52
- Pa.each.should be_an_instance_of Enumerator
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)
61
- end
62
-
63
- it "each(.) return 'foo' not '.foo'" do
64
- Pa.each.with_object([]){|pa,m| m<<pa.p}.sort.should == %w(.fa dira fa fa~)
65
- end
66
-
67
- it "each(nodot: true) -> list all files except dot file" do
68
- Pa.each(nodot: true).with_object([]){|pa,m|m<<pa.b}.sort.should == %w(dira fa fa~)
69
- end
70
-
71
- it "each_r -> Enumerator" do
72
- Pa.each_r.should be_an_instance_of Enumerator
73
- Pa.each_r.with_object([]){|(pa,r),m|m<<r}.sort.should == %w(.fa dira dira/dirb dira/dirb/b fa fa~)
74
- end
75
- end
76
-
77
-
78
- end
@@ -1,136 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Pa do
4
-
5
- describe "#dir2" do
6
- it "runs ok" do
7
- Pa('/home/foo').dir2.should be_an_instance_of Pa
8
- end
9
- end
10
-
11
- describe "#absoulte2" do
12
- it "runs ok" do
13
- Pa('.').absolute2.should be_an_instance_of Pa
14
- end
15
- end
16
-
17
- describe "pwd2" do
18
- it "runs ok" do
19
- Pa.pwd2.should be_an_instance_of Pa
20
- end
21
- end
22
-
23
- describe ".shorten" do
24
- it "short /home/usr/file into ~/file" do
25
- ENV["HOME"] = "/home/foo"
26
- Pa.shorten("/home/foo/file").should == "~/file"
27
- end
28
-
29
- it "not short /home/other-user/file" do
30
- ENV["HOME"] = "/home/foo"
31
- Pa.shorten("/home/bar/file").should == "/home/bar/file"
32
- end
33
- end
34
-
35
- describe "NAME_EXT_PAT" do
36
- it "matchs `foo.bar'" do
37
- "foo.bar".match(Pa::NAME_EXT_PAT).captures.should == %w(foo bar)
38
- end
39
-
40
- it "matchs `foo'" do
41
- "foo".match(Pa::NAME_EXT_PAT).captures.should == ["foo", nil]
42
- end
43
-
44
- end
45
-
46
- describe "basename" do
47
- it "get a basename of a path" do
48
- Pa.basename("/home/foo").should == "foo"
49
- end
50
-
51
- it "get name, ext with :ext => true" do
52
- Pa.basename("/home/foo.bar", ext: true).should == ["foo", "bar"]
53
- end
54
-
55
- end
56
-
57
- describe '.parent' do
58
- before :each do
59
- @path = "/home/foo/a.txt"
60
- end
61
-
62
- it "return parent path" do
63
- Pa.parent(@path).should == "/home/foo"
64
- end
65
-
66
- it "return parent upto 2 level path" do
67
- Pa.parent(@path, 2).should == "/home"
68
- end
69
- end
70
-
71
- describe "#==" do
72
- it "runs ok" do
73
- (Pa('/home') == Pa('/home')).should be_true
74
- end
75
- end
76
-
77
- describe "#+" do
78
- it "runs ok" do
79
- (Pa('/home')+'~').should == Pa('/home~')
80
- end
81
- end
82
-
83
- describe "#sub" do
84
- it "runs ok" do
85
- Pa('/home/foo').sub(/o/,'').should == Pa('/hme/foo')
86
- end
87
- end
88
-
89
- describe "#sub!" do
90
- it "runs ok" do
91
- pa = Pa('/home/foo')
92
- pa.sub!(/o/,'')
93
- pa.should == Pa('/hme/foo')
94
- end
95
- end
96
-
97
- describe "#gsub" do
98
- it "runs ok" do
99
- Pa('/home/foo').gsub(/o/,'').should == Pa('/hme/f')
100
- end
101
- end
102
-
103
- describe "#gsub!" do
104
- it "runs ok" do
105
- pa = Pa('/home/foo')
106
- pa.gsub!(/o/,'')
107
- pa.should == Pa('/hme/f')
108
- end
109
- end
110
-
111
- describe "#match" do
112
- it "runs ok" do
113
- Pa('/home/foo').match(/foo/)[0].should == 'foo'
114
- end
115
- end
116
-
117
- describe "#start_with?" do
118
- it "runs ok" do
119
- Pa('/home/foo').start_with?('/home').should be_true
120
- end
121
- end
122
-
123
- describe "#end_with?" do
124
- it "runs ok" do
125
- Pa('/home/foo').end_with?('foo').should be_true
126
- end
127
- end
128
-
129
- describe "#=~" do
130
- it "runs ok" do
131
- (Pa('/home/foo') =~ /foo/).should be_true
132
- end
133
- end
134
-
135
-
136
- end
@@ -1,7 +0,0 @@
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
@@ -1,32 +0,0 @@
1
- require "spec_helper"
2
- require "tagen/yaml"
3
- require "tagen/core"
4
- require "tmpdir"
5
- require "fileutils"
6
-
7
- describe YAML do
8
- before :all do
9
- @curdir = Dir.pwd
10
- @tmpdir = Dir.mktmpdir
11
- Dir.chdir @tmpdir
12
- end
13
-
14
- after :all do
15
- Dir.chdir @curdir
16
- FileUtils.rm_r @tmpdir
17
- end
18
-
19
- describe ".dump" do
20
- it "support Pa" do
21
- YAML.dump("foo", Pa('a'))
22
- File.read('a').should =~ /foo/
23
- end
24
- end
25
-
26
- describe ".load" do
27
- it "support Pa" do
28
- YAML.dump('foo', open('b', 'w+'))
29
- YAML.load(Pa('b')).should == 'foo'
30
- end
31
- end
32
- end