fs 0.1.1 → 0.1.2
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/.rspec +1 -0
- data/Gemfile +1 -3
- data/README.mdown +5 -5
- data/Rakefile +1 -1
- data/fs.gemspec +5 -4
- data/lib/fs/alias.rb +4 -3
- data/lib/fs/base.rb +16 -16
- data/lib/fs/version.rb +1 -1
- data/spec/alias_spec.rb +3 -3
- data/spec/base_spec.rb +98 -98
- data/spec/test_dir_spec.rb +5 -5
- metadata +66 -56
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/Gemfile
CHANGED
data/README.mdown
CHANGED
@@ -8,14 +8,14 @@ This Gem shouldn't reinvent the wheel or be a replacement.
|
|
8
8
|
But in Ruby working with the filesystem really hurts!
|
9
9
|
|
10
10
|
In your toolbox are at least `File`, `Dir`, `FileUtils`, `Find`, and maybe some more.
|
11
|
-
Good tools, but to complicated for most cases.
|
11
|
+
Good tools, but to complicated for most cases.
|
12
12
|
It's not about piping, or copying the shell as it is.
|
13
|
-
But think about a simple `ls` in the shell, than how you would do this in Ruby.
|
13
|
+
But think about a simple `ls` in the shell, than how you would do this in Ruby.
|
14
14
|
Got the idea?
|
15
15
|
|
16
16
|
## Solution
|
17
17
|
|
18
|
-
`FS` gathers the cluttered methods for working with files and dirs. Internally
|
18
|
+
`FS` gathers the cluttered methods for working with files and dirs. Internally
|
19
19
|
using the good old standard library, but providing simple methods in a single place.
|
20
20
|
|
21
21
|
## Examples
|
@@ -34,7 +34,7 @@ using the good old standard library, but providing simple methods in a single pl
|
|
34
34
|
|
35
35
|
## Aliases
|
36
36
|
|
37
|
-
Although verbose method names are good, there are some aliases for unix shell
|
37
|
+
Although verbose method names are good, there are some aliases for unix shell
|
38
38
|
commands (unsorted).
|
39
39
|
|
40
40
|
- ls => list
|
@@ -65,5 +65,5 @@ Here is my mind … here is my mind …
|
|
65
65
|
|
66
66
|
## BTW
|
67
67
|
|
68
|
-
If you need a replacement for the shell in pure ruby, than have a look at
|
68
|
+
If you need a replacement for the shell in pure ruby, than have a look at
|
69
69
|
[Rush](http://rush.heroku.com/).
|
data/Rakefile
CHANGED
data/fs.gemspec
CHANGED
@@ -12,12 +12,13 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.summary = %q{Work with your filesystem!}
|
13
13
|
s.description = %q{FS gathers the cluttered methods for working with files and dirs. Internally using the good old standard library, but providing simple methods in a single place.}
|
14
14
|
|
15
|
-
s.add_development_dependency 'rspec', '2.5.0'
|
16
|
-
s.add_development_dependency 'yard', '0.6.5'
|
17
|
-
s.add_development_dependency 'bluecloth', '2.1.0'
|
18
|
-
|
19
15
|
s.files = `git ls-files`.split("\n")
|
20
16
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
17
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
22
18
|
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_development_dependency 'rake', '0.9.2.2'
|
21
|
+
s.add_development_dependency 'rspec', '2.7.0'
|
22
|
+
s.add_development_dependency 'yard', '0.7.2'
|
23
|
+
s.add_development_dependency 'bluecloth', '2.2.0'
|
23
24
|
end
|
data/lib/fs/alias.rb
CHANGED
@@ -15,15 +15,16 @@ module FS
|
|
15
15
|
:ln => :link,
|
16
16
|
:dir? => :directory?,
|
17
17
|
:expand => :expand_path,
|
18
|
+
:[] => :join,
|
18
19
|
}
|
19
|
-
|
20
|
+
|
20
21
|
def self.included(base)
|
21
22
|
base.class_eval do
|
22
23
|
ALIASES.each do |shortcut, original|
|
23
|
-
alias_method shortcut, original
|
24
|
+
alias_method shortcut, original
|
24
25
|
end
|
25
26
|
end
|
26
27
|
end
|
27
|
-
|
28
|
+
|
28
29
|
end
|
29
30
|
end
|
data/lib/fs/base.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module FS
|
2
2
|
module Base
|
3
|
-
|
3
|
+
|
4
4
|
# FileUtils.touch
|
5
5
|
def touch(*files)
|
6
6
|
FileUtils.touch(files)
|
@@ -44,7 +44,7 @@ module FS
|
|
44
44
|
# FileUtils#mv
|
45
45
|
def move(*froms, to)
|
46
46
|
froms.each do |from|
|
47
|
-
FileUtils.mv(from, to)
|
47
|
+
FileUtils.mv(from, to)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -55,7 +55,7 @@ module FS
|
|
55
55
|
FileUtils.cp(from, to)
|
56
56
|
end
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
# Creates hard links for files and symbolic links for dirs
|
60
60
|
#
|
61
61
|
# FileUtils#ln or FileUtils#ln_s
|
@@ -66,7 +66,7 @@ module FS
|
|
66
66
|
FileUtils.ln(from, to)
|
67
67
|
end
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
# FileUtils#rm
|
71
71
|
def remove(*pathes)
|
72
72
|
FileUtils.rm(pathes)
|
@@ -106,17 +106,17 @@ module FS
|
|
106
106
|
def changedir(dir)
|
107
107
|
Dir.chdir(dir)
|
108
108
|
end
|
109
|
-
|
109
|
+
|
110
110
|
# Dir#pwd
|
111
111
|
def currentdir
|
112
112
|
Dir.pwd
|
113
113
|
end
|
114
|
-
|
114
|
+
|
115
115
|
# tmpdir / Dir.tmpdir
|
116
116
|
def tempdir
|
117
117
|
Dir.tmpdir
|
118
118
|
end
|
119
|
-
|
119
|
+
|
120
120
|
# TODO: use separate options for prefix, suffix and target_dir
|
121
121
|
# tmpdir / Dir.mktmpdir
|
122
122
|
def maketempdir(prefix_suffix=nil, parent_dir=nil)
|
@@ -200,26 +200,26 @@ module FS
|
|
200
200
|
return '' if path == '/' || path == '.'
|
201
201
|
base = File.basename(path)
|
202
202
|
ext = File.extname(path)
|
203
|
-
ext.empty? ? base :base[0...-ext.size]
|
203
|
+
ext.empty? ? base :base[0...-ext.size]
|
204
204
|
end
|
205
205
|
|
206
206
|
# "tmp/foo/bar.todo" => ["tmp/foo", "bar", ".todo"]
|
207
207
|
def splitname(path)
|
208
208
|
[dirname(path), filename(path), extname(path)]
|
209
209
|
end
|
210
|
-
|
210
|
+
|
211
211
|
# __FILE__ of the caller
|
212
212
|
def this_file
|
213
213
|
caller_file(caller)
|
214
214
|
end
|
215
|
-
|
215
|
+
|
216
216
|
# File.dirname(__FILE__) of the caller
|
217
217
|
def this_dir
|
218
218
|
File.dirname(caller_file(caller))
|
219
219
|
end
|
220
220
|
|
221
221
|
private
|
222
|
-
|
222
|
+
|
223
223
|
def assert_dir(path)
|
224
224
|
raise "not a directory: #{path}" unless File.directory?(path)
|
225
225
|
end
|
@@ -231,16 +231,16 @@ module FS
|
|
231
231
|
path.gsub(regexp, '')
|
232
232
|
end
|
233
233
|
end
|
234
|
-
|
234
|
+
|
235
235
|
def visit_tree(output, parent_path, indent, arm, tie, node)
|
236
236
|
output << "#{indent}#{arm}#{tie}#{node}"
|
237
|
-
|
237
|
+
|
238
238
|
node_path = File.expand_path(node, parent_path)
|
239
239
|
return unless File.directory?(node_path) && File.readable?(node_path)
|
240
|
-
|
240
|
+
|
241
241
|
subnodes = FS.list(node_path)
|
242
242
|
return if subnodes.empty?
|
243
|
-
|
243
|
+
|
244
244
|
arms = Array.new(subnodes.length - 1, '|') << '`'
|
245
245
|
arm_to_indent = {
|
246
246
|
'' => '',
|
@@ -268,6 +268,6 @@ module FS
|
|
268
268
|
[file, line, method]
|
269
269
|
end
|
270
270
|
end
|
271
|
-
|
271
|
+
|
272
272
|
end
|
273
273
|
end
|
data/lib/fs/version.rb
CHANGED
data/spec/alias_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe FS::Alias do
|
4
|
-
|
4
|
+
|
5
5
|
FS::Alias::ALIASES.each do |shortcut, original|
|
6
6
|
it "#{shortcut} exists for #{original}" do
|
7
7
|
FS.respond_to?(shortcut).should be_true
|
@@ -12,6 +12,6 @@ describe FS::Alias do
|
|
12
12
|
s.parameters.should eql(o.parameters)
|
13
13
|
end
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
end
|
17
|
-
|
17
|
+
|
data/spec/base_spec.rb
CHANGED
@@ -1,54 +1,54 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe FS::Base do
|
4
|
-
|
5
|
-
describe 'touch' do
|
4
|
+
|
5
|
+
describe '::touch' do
|
6
6
|
it 'touches a single file' do
|
7
7
|
file = 'foobar.txt'
|
8
8
|
FS.touch(file)
|
9
|
-
File.exist?(file).should be_true
|
9
|
+
File.exist?(file).should be_true
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
it 'accepts multiple files' do
|
13
13
|
FS.touch('foo.txt', 'bar.txt')
|
14
14
|
File.exist?('foo.txt').should be_true
|
15
15
|
File.exist?('bar.txt').should be_true
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
it 'accepts a list of files' do
|
19
19
|
files = ['foo.txt', 'bar.txt']
|
20
20
|
FS.touch(files)
|
21
21
|
files.each do |file|
|
22
|
-
File.exist?(file).should be_true
|
22
|
+
File.exist?(file).should be_true
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
26
|
-
|
27
|
-
describe 'makedir' do
|
26
|
+
|
27
|
+
describe '::makedir' do
|
28
28
|
it 'creates a dir' do
|
29
29
|
FS.makedir('foo')
|
30
30
|
File.directory?('foo').should be_true
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
it 'accepts multiple dirs' do
|
34
34
|
FS.makedir('foo', 'bar')
|
35
35
|
File.directory?('foo').should be_true
|
36
36
|
File.directory?('bar').should be_true
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
it 'fails if a parent dir is missing' do
|
40
40
|
lambda {FS.makedir('foo/bar')}.should raise_error
|
41
41
|
end
|
42
42
|
end
|
43
|
-
|
44
|
-
describe 'makedirs' do
|
43
|
+
|
44
|
+
describe '::makedirs' do
|
45
45
|
it 'creates all missing parent dirs' do
|
46
46
|
FS.makedirs 'foo/bar/baz'
|
47
47
|
File.directory?('foo').should be_true
|
48
48
|
File.directory?('foo/bar').should be_true
|
49
49
|
File.directory?('foo/bar/baz').should be_true
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
it 'accepts multiple dirs' do
|
53
53
|
FS.makedirs('foo/bar', 'baz/yep')
|
54
54
|
File.directory?('foo').should be_true
|
@@ -57,28 +57,28 @@ describe FS::Base do
|
|
57
57
|
File.directory?('baz/yep').should be_true
|
58
58
|
end
|
59
59
|
end
|
60
|
-
|
61
|
-
describe 'removedir' do
|
60
|
+
|
61
|
+
describe '::removedir' do
|
62
62
|
it 'removes a dir' do
|
63
63
|
FS.makedir('foo')
|
64
64
|
FS.removedir('foo')
|
65
65
|
File.exist?('foo').should be_false
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
it 'fails if dir not empty' do
|
69
69
|
FS.makedirs('foo/dir')
|
70
70
|
FS.touch('foo/file')
|
71
71
|
lambda {FS.removedir('foo')}.should raise_error
|
72
72
|
end
|
73
73
|
end
|
74
|
-
|
75
|
-
describe 'removedirs' do
|
74
|
+
|
75
|
+
describe '::removedirs' do
|
76
76
|
it 'removes a dir' do
|
77
77
|
FS.makedir('foo')
|
78
78
|
FS.removedirs('foo')
|
79
79
|
File.exist?('foo').should be_false
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
it 'removes a dir even if something is inside' do
|
83
83
|
FS.makedirs('foo/dir')
|
84
84
|
FS.touch('foo/file')
|
@@ -86,18 +86,18 @@ describe FS::Base do
|
|
86
86
|
File.exist?('foo').should be_false
|
87
87
|
end
|
88
88
|
end
|
89
|
-
|
90
|
-
describe 'list' do
|
89
|
+
|
90
|
+
describe '::list' do
|
91
91
|
it 'returns an empty list if there are no files' do
|
92
92
|
FS.list.should be_empty
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
95
|
it 'lists all files and dirs (without . and ..)' do
|
96
96
|
FS.touch('file')
|
97
97
|
FS.makedir('dir')
|
98
98
|
FS.list.should eql(['dir', 'file'])
|
99
99
|
end
|
100
|
-
|
100
|
+
|
101
101
|
it 'lists files and dirs in the current dir' do
|
102
102
|
FS.makedir('foo')
|
103
103
|
FS.makedir('foo/dir')
|
@@ -105,7 +105,7 @@ describe FS::Base do
|
|
105
105
|
Dir.chdir('foo')
|
106
106
|
FS.list.should eql(['dir', 'file'])
|
107
107
|
end
|
108
|
-
|
108
|
+
|
109
109
|
it 'globs files and dirs' do
|
110
110
|
FS.touch('file.txt')
|
111
111
|
FS.touch('file.rb')
|
@@ -113,7 +113,7 @@ describe FS::Base do
|
|
113
113
|
FS.makedir('dir.rb')
|
114
114
|
FS.list('.', '*.txt').should eql(['dir.txt', 'file.txt'])
|
115
115
|
end
|
116
|
-
|
116
|
+
|
117
117
|
it 'globs files and dirs' do
|
118
118
|
FS.touch('file.txt')
|
119
119
|
FS.touch('file.rb')
|
@@ -121,14 +121,14 @@ describe FS::Base do
|
|
121
121
|
FS.makedir('dir.rb')
|
122
122
|
FS.list('.', '*.txt').should eql(['dir.txt', 'file.txt'])
|
123
123
|
end
|
124
|
-
|
124
|
+
|
125
125
|
it 'lists files and dirs in a subdir' do
|
126
126
|
FS.makedir('foo')
|
127
127
|
FS.makedir('foo/dir')
|
128
128
|
FS.touch('foo/file')
|
129
129
|
FS.list('foo').should eql(['dir', 'file'])
|
130
130
|
end
|
131
|
-
|
131
|
+
|
132
132
|
it 'globs files and dirs in a subdir' do
|
133
133
|
FS.makedir('foo')
|
134
134
|
FS.touch('foo/file.txt')
|
@@ -138,12 +138,12 @@ describe FS::Base do
|
|
138
138
|
FS.list('foo', '*.txt').should eql(['dir.txt', 'file.txt'])
|
139
139
|
end
|
140
140
|
end
|
141
|
-
|
142
|
-
describe 'find' do
|
141
|
+
|
142
|
+
describe '::find' do
|
143
143
|
it 'returns an empty list if there are no files' do
|
144
144
|
FS.find('.').should be_empty
|
145
145
|
end
|
146
|
-
|
146
|
+
|
147
147
|
it 'finds files in all subdirs' do
|
148
148
|
FS.makedirs('one/two/three')
|
149
149
|
FS.touch('one/file.one')
|
@@ -156,7 +156,7 @@ describe FS::Base do
|
|
156
156
|
'one/two/three/file.three'
|
157
157
|
])
|
158
158
|
end
|
159
|
-
|
159
|
+
|
160
160
|
it 'globs files in all subdirs' do
|
161
161
|
FS.makedirs('one/two/three')
|
162
162
|
FS.touch('one/file.one')
|
@@ -167,14 +167,14 @@ describe FS::Base do
|
|
167
167
|
])
|
168
168
|
end
|
169
169
|
end
|
170
|
-
|
171
|
-
describe 'move' do
|
170
|
+
|
171
|
+
describe '::move' do
|
172
172
|
it 'renames a file' do
|
173
173
|
FS.touch('foo.txt')
|
174
174
|
FS.move('foo.txt', 'bar.txt')
|
175
175
|
FS.list.should eql(['bar.txt'])
|
176
176
|
end
|
177
|
-
|
177
|
+
|
178
178
|
it 'moves a file' do
|
179
179
|
FS.touch('foo.txt')
|
180
180
|
FS.makedirs('tmp')
|
@@ -182,7 +182,7 @@ describe FS::Base do
|
|
182
182
|
FS.list.should eql(['tmp'])
|
183
183
|
FS.list('tmp').should eql(['foo.txt'])
|
184
184
|
end
|
185
|
-
|
185
|
+
|
186
186
|
it 'moves files and dirs' do
|
187
187
|
FS.touch('file')
|
188
188
|
FS.makedir('dir')
|
@@ -192,8 +192,8 @@ describe FS::Base do
|
|
192
192
|
FS.list('tmp').should eql(['dir', 'file'])
|
193
193
|
end
|
194
194
|
end
|
195
|
-
|
196
|
-
describe 'copy' do
|
195
|
+
|
196
|
+
describe '::copy' do
|
197
197
|
it 'copies a file' do
|
198
198
|
FS.write('foo.txt', 'lala')
|
199
199
|
FS.copy('foo.txt', 'bar.txt')
|
@@ -207,7 +207,7 @@ describe FS::Base do
|
|
207
207
|
FS.read('foo.txt').should eql('lala')
|
208
208
|
FS.read('bar.txt').should eql('lala')
|
209
209
|
end
|
210
|
-
|
210
|
+
|
211
211
|
it 'copies a file to a dir' do
|
212
212
|
FS.write('foo.txt', 'lala')
|
213
213
|
FS.makedir('dir')
|
@@ -216,15 +216,15 @@ describe FS::Base do
|
|
216
216
|
File.exist?('dir/bar.txt').should be_true
|
217
217
|
end
|
218
218
|
end
|
219
|
-
|
220
|
-
describe 'link' do
|
219
|
+
|
220
|
+
describe '::link' do
|
221
221
|
it 'links to files' do
|
222
222
|
FS.touch('foo.txt')
|
223
223
|
FS.link('foo.txt', 'bar.txt')
|
224
224
|
FS.write('foo.txt', 'lala')
|
225
225
|
FS.read('bar.txt').should eql('lala')
|
226
226
|
end
|
227
|
-
|
227
|
+
|
228
228
|
it 'links to dirs' do
|
229
229
|
FS.makedir('foo')
|
230
230
|
FS.link('foo', 'bar')
|
@@ -232,8 +232,8 @@ describe FS::Base do
|
|
232
232
|
FS.list('bar').should eql(['file'])
|
233
233
|
end
|
234
234
|
end
|
235
|
-
|
236
|
-
describe 'remove' do
|
235
|
+
|
236
|
+
describe '::remove' do
|
237
237
|
it 'removes files' do
|
238
238
|
FS.touch('file')
|
239
239
|
FS.remove('file')
|
@@ -246,12 +246,12 @@ describe FS::Base do
|
|
246
246
|
FS.remove('file.a', 'file.b')
|
247
247
|
FS.list.should be_empty
|
248
248
|
end
|
249
|
-
|
249
|
+
|
250
250
|
it 'fails on dirs' do
|
251
251
|
FS.makedir('dir')
|
252
252
|
lambda {FS.remove('dir')}.should raise_error
|
253
253
|
end
|
254
|
-
|
254
|
+
|
255
255
|
# FIXME: fakefs
|
256
256
|
# it 'fails if the dir is not empty' do
|
257
257
|
# FS.makedir('/foo')
|
@@ -259,52 +259,52 @@ describe FS::Base do
|
|
259
259
|
# lambda {FS.remove('/foo')}.should raise_error
|
260
260
|
# end
|
261
261
|
end
|
262
|
-
|
263
|
-
describe 'write' do
|
262
|
+
|
263
|
+
describe '::write' do
|
264
264
|
it 'writes content from a string' do
|
265
265
|
FS.write('foo.txt', 'bar')
|
266
266
|
File.open('foo.txt').read.should eql('bar')
|
267
267
|
end
|
268
|
-
|
268
|
+
|
269
269
|
it 'writes content from a block' do
|
270
270
|
FS.write('foo.txt') {|f| f.write 'bar' }
|
271
271
|
File.open('foo.txt').read.should eql('bar')
|
272
272
|
end
|
273
273
|
end
|
274
|
-
|
275
|
-
describe 'read' do
|
274
|
+
|
275
|
+
describe '::read' do
|
276
276
|
it 'reads the content to a string' do
|
277
277
|
File.open('foo.txt', 'w') {|f| f.write 'bar' }
|
278
278
|
FS.read('foo.txt').should eql('bar')
|
279
279
|
end
|
280
|
-
|
280
|
+
|
281
281
|
it 'reads the content to a block' do
|
282
282
|
File.open('foo.txt', 'w') {|f| f.write 'bar' }
|
283
283
|
FS.read('foo.txt') {|f| f.read.should eql('bar')}
|
284
284
|
end
|
285
285
|
end
|
286
|
-
|
287
|
-
describe 'root' do
|
286
|
+
|
287
|
+
describe '::root' do
|
288
288
|
it 'always returns /' do
|
289
289
|
FS.root.should eql('/')
|
290
290
|
end
|
291
291
|
end
|
292
|
-
|
293
|
-
describe 'home' do
|
292
|
+
|
293
|
+
describe '::home' do
|
294
294
|
it 'returns the home of the current user' do
|
295
295
|
FS.home.should match(/\/#{Etc.getlogin}$/)
|
296
296
|
end
|
297
|
-
|
297
|
+
|
298
298
|
it 'returns the home of another user' do
|
299
299
|
FS.home('root').should match(/\/root$/)
|
300
300
|
end
|
301
301
|
end
|
302
302
|
|
303
|
-
describe 'currentdir' do
|
303
|
+
describe '::currentdir' do
|
304
304
|
it 'returns the current dir' do
|
305
305
|
FS.currentdir.should eql(@test_dir)
|
306
306
|
end
|
307
|
-
|
307
|
+
|
308
308
|
it 'works after dir was changed' do
|
309
309
|
here = FS.currentdir
|
310
310
|
FS.makedir('foo')
|
@@ -312,8 +312,8 @@ describe FS::Base do
|
|
312
312
|
FS.currentdir.should eql(File.join(here, 'foo'))
|
313
313
|
end
|
314
314
|
end
|
315
|
-
|
316
|
-
describe 'changedir' do
|
315
|
+
|
316
|
+
describe '::changedir' do
|
317
317
|
it 'change the current dir' do
|
318
318
|
here = Dir.pwd
|
319
319
|
FS.makedir('foo')
|
@@ -321,8 +321,8 @@ describe FS::Base do
|
|
321
321
|
Dir.pwd.should eql(File.join(here, 'foo'))
|
322
322
|
end
|
323
323
|
end
|
324
|
-
|
325
|
-
describe 'tree' do
|
324
|
+
|
325
|
+
describe '::tree' do
|
326
326
|
before(:each) do
|
327
327
|
FS.touch('a.file')
|
328
328
|
FS.makedir('baz')
|
@@ -361,8 +361,8 @@ TXT
|
|
361
361
|
end
|
362
362
|
|
363
363
|
end
|
364
|
-
|
365
|
-
describe 'exist?' do
|
364
|
+
|
365
|
+
describe '::exist?' do
|
366
366
|
it 'returns if a path exist' do
|
367
367
|
FS.makedir('foo')
|
368
368
|
FS.touch('bar')
|
@@ -372,7 +372,7 @@ TXT
|
|
372
372
|
end
|
373
373
|
end
|
374
374
|
|
375
|
-
describe 'directory?' do
|
375
|
+
describe '::directory?' do
|
376
376
|
it 'checks for a directory' do
|
377
377
|
FS.makedir('foo')
|
378
378
|
FS.touch('bar')
|
@@ -381,8 +381,8 @@ TXT
|
|
381
381
|
FS.directory?('baz').should be_false
|
382
382
|
end
|
383
383
|
end
|
384
|
-
|
385
|
-
describe 'file?' do
|
384
|
+
|
385
|
+
describe '::file?' do
|
386
386
|
it 'checks for a file' do
|
387
387
|
FS.makedir('foo')
|
388
388
|
FS.touch('bar')
|
@@ -391,20 +391,20 @@ TXT
|
|
391
391
|
FS.file?('baz').should be_false
|
392
392
|
end
|
393
393
|
end
|
394
|
-
|
395
|
-
describe 'empty?' do
|
394
|
+
|
395
|
+
describe '::empty?' do
|
396
396
|
it 'returns nil if the path does not exist' do
|
397
397
|
FS.exist?('foobar').should be_false
|
398
398
|
FS.empty?('foobar').should be_nil
|
399
399
|
end
|
400
|
-
|
400
|
+
|
401
401
|
it 'returns if a file is empty' do
|
402
402
|
FS.touch('empty.file')
|
403
403
|
FS.write('content.file', 'something')
|
404
404
|
FS.empty?('empty.file').should be_true
|
405
405
|
FS.empty?('content.file').should be_false
|
406
406
|
end
|
407
|
-
|
407
|
+
|
408
408
|
it 'returns if a dir is empty' do
|
409
409
|
FS.mkdir('empty.dir')
|
410
410
|
FS.mkdir('content.dir')
|
@@ -413,16 +413,16 @@ TXT
|
|
413
413
|
FS.empty?('content.dir').should be_false
|
414
414
|
end
|
415
415
|
end
|
416
|
-
|
417
|
-
describe 'join' do
|
416
|
+
|
417
|
+
describe '::join' do
|
418
418
|
it 'joins pathes' do
|
419
419
|
FS.join('foo', 'bar').should eql('foo/bar')
|
420
420
|
FS.join('foo', '/bar').should eql('foo/bar')
|
421
421
|
FS.join('foo/', 'bar').should eql('foo/bar')
|
422
|
-
end
|
422
|
+
end
|
423
423
|
end
|
424
|
-
|
425
|
-
describe 'expand_path' do
|
424
|
+
|
425
|
+
describe '::expand_path' do
|
426
426
|
it 'expands pathes' do
|
427
427
|
here = File.expand_path('.')
|
428
428
|
FS.expand_path('.').should eql(here)
|
@@ -431,7 +431,7 @@ TXT
|
|
431
431
|
end
|
432
432
|
end
|
433
433
|
|
434
|
-
describe 'absolute?' do
|
434
|
+
describe '::absolute?' do
|
435
435
|
it 'checks for an absolute path' do
|
436
436
|
FS.absolute?('/').should be_true
|
437
437
|
FS.absolute?('/foo').should be_true
|
@@ -440,7 +440,7 @@ TXT
|
|
440
440
|
end
|
441
441
|
end
|
442
442
|
|
443
|
-
describe 'dirname' do
|
443
|
+
describe '::dirname' do
|
444
444
|
it 'extracts the dir of a path' do
|
445
445
|
FS.dirname('tmp/foo/bar.todo').should eql('tmp/foo')
|
446
446
|
FS.dirname('tmp/foo').should eql('tmp')
|
@@ -451,7 +451,7 @@ TXT
|
|
451
451
|
end
|
452
452
|
end
|
453
453
|
|
454
|
-
describe 'basename' do
|
454
|
+
describe '::basename' do
|
455
455
|
it 'extracts the base of a path' do
|
456
456
|
FS.basename('tmp/foo/bar.todo').should eql('bar.todo')
|
457
457
|
FS.basename('tmp/foo').should eql('foo')
|
@@ -461,8 +461,8 @@ TXT
|
|
461
461
|
FS.basename('.').should eql('.')
|
462
462
|
end
|
463
463
|
end
|
464
|
-
|
465
|
-
describe 'filename' do
|
464
|
+
|
465
|
+
describe '::filename' do
|
466
466
|
it 'extracts the filename of a path' do
|
467
467
|
FS.filename('tmp/foo/bar.todo').should eql('bar')
|
468
468
|
FS.filename('tmp/foo').should eql('foo')
|
@@ -473,8 +473,8 @@ TXT
|
|
473
473
|
FS.filename('foo.bar.txt').should eql('foo.bar')
|
474
474
|
end
|
475
475
|
end
|
476
|
-
|
477
|
-
describe 'extname' do
|
476
|
+
|
477
|
+
describe '::extname' do
|
478
478
|
it 'extracts the extension of a path' do
|
479
479
|
FS.extname('tmp/foo/bar.todo').should eql('.todo')
|
480
480
|
FS.extname('tmp/foo').should eql('')
|
@@ -485,8 +485,8 @@ TXT
|
|
485
485
|
FS.extname('foo.bar.txt').should eql('.txt')
|
486
486
|
end
|
487
487
|
end
|
488
|
-
|
489
|
-
describe 'splitname' do
|
488
|
+
|
489
|
+
describe '::splitname' do
|
490
490
|
it 'splits the parts of a path' do
|
491
491
|
FS.splitname('tmp/foo/bar.todo').should eql(["tmp/foo", "bar", ".todo"])
|
492
492
|
FS.splitname('tmp/foo').should eql(['tmp', 'foo', ''])
|
@@ -496,26 +496,26 @@ TXT
|
|
496
496
|
FS.splitname('.').should eql(['.', '', ''])
|
497
497
|
end
|
498
498
|
end
|
499
|
-
|
500
|
-
describe 'this_file' do
|
499
|
+
|
500
|
+
describe '::this_file' do
|
501
501
|
it 'returns this file' do
|
502
502
|
FS.this_file.should eql(__FILE__)
|
503
503
|
end
|
504
504
|
end
|
505
505
|
|
506
|
-
describe 'this_dir' do
|
506
|
+
describe '::this_dir' do
|
507
507
|
it 'returns the dir of this file' do
|
508
508
|
FS.this_dir.should eql(File.dirname(__FILE__))
|
509
509
|
end
|
510
510
|
end
|
511
|
-
|
512
|
-
describe 'tempdir' do
|
511
|
+
|
512
|
+
describe '::tempdir' do
|
513
513
|
it 'returns the current temp dir' do
|
514
514
|
FS.tempdir.should eql(Dir.tmpdir)
|
515
515
|
end
|
516
516
|
end
|
517
|
-
|
518
|
-
describe 'maketempdir' do
|
517
|
+
|
518
|
+
describe '::maketempdir' do
|
519
519
|
it 'creates a new dir in the default temp dir' do
|
520
520
|
dir = FS.maketempdir
|
521
521
|
File.exist?(dir).should be_true
|
@@ -523,7 +523,7 @@ TXT
|
|
523
523
|
Dir.entries(dir).should eql([".", ".."])
|
524
524
|
Dir.entries(Dir.tmpdir).should include(File.basename(dir))
|
525
525
|
end
|
526
|
-
|
526
|
+
|
527
527
|
it 'creates a new temp dir with the given prefix' do
|
528
528
|
dir = FS.maketempdir('my_dir')
|
529
529
|
dir.should match(/\/my_dir/)
|
@@ -532,7 +532,7 @@ TXT
|
|
532
532
|
Dir.entries(dir).should eql([".", ".."])
|
533
533
|
Dir.entries(Dir.tmpdir).should include(File.basename(dir))
|
534
534
|
end
|
535
|
-
|
535
|
+
|
536
536
|
it 'creates a new temp dir inside of the given dir' do
|
537
537
|
parent_dir = FS.maketempdir('parent_dir')
|
538
538
|
dir = FS.maketempdir(nil, parent_dir)
|
@@ -542,8 +542,8 @@ TXT
|
|
542
542
|
Dir.entries(parent_dir).should include(File.basename(dir))
|
543
543
|
end
|
544
544
|
end
|
545
|
-
|
546
|
-
describe 'maketempfile' do
|
545
|
+
|
546
|
+
describe '::maketempfile' do
|
547
547
|
it 'creates a new file in the default temp dir' do
|
548
548
|
file = FS.maketempfile
|
549
549
|
FS.exist?(file).should be_true
|
@@ -560,7 +560,7 @@ TXT
|
|
560
560
|
FS.empty?(file).should be_true
|
561
561
|
FS.list(Dir.tmpdir).should include(File.basename(file))
|
562
562
|
end
|
563
|
-
|
563
|
+
|
564
564
|
it 'creates a new temp file inside of the given dir' do
|
565
565
|
parent_dir = FS.maketempdir('parent_dir')
|
566
566
|
file = FS.maketempfile(nil, parent_dir)
|
@@ -570,5 +570,5 @@ TXT
|
|
570
570
|
FS.list(parent_dir).should include(File.basename(file))
|
571
571
|
end
|
572
572
|
end
|
573
|
-
|
573
|
+
|
574
574
|
end
|
data/spec/test_dir_spec.rb
CHANGED
@@ -5,23 +5,23 @@ describe FS do
|
|
5
5
|
it 'is absolute' do
|
6
6
|
Pathname.new(@test_dir).should be_absolute
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
it 'is created' do
|
10
10
|
File.exist?(@test_dir).should be_true
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
it 'is a directory' do
|
14
14
|
File.directory?(@test_dir).should be_true
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
it 'is empty' do
|
18
18
|
Dir.entries(@test_dir).should eql([".", ".."])
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
it 'is the current dir' do
|
22
22
|
File.expand_path(Dir.pwd).should eql(@test_dir)
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
it 'is deleted when not empty' do
|
26
26
|
filename = 'test.file'
|
27
27
|
FileUtils.touch(filename)
|
metadata
CHANGED
@@ -1,62 +1,70 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: fs
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
4
5
|
prerelease:
|
5
|
-
version: 0.1.1
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
8
|
-
-
|
7
|
+
authors:
|
8
|
+
- Bernd Jünger
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
date: 2011-11-04 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: &2157319500 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - =
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.9.2.2
|
22
|
+
type: :development
|
18
23
|
prerelease: false
|
19
|
-
|
24
|
+
version_requirements: *2157319500
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &2157319020 !ruby/object:Gem::Requirement
|
20
28
|
none: false
|
21
|
-
requirements:
|
22
|
-
- -
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version: 2.
|
29
|
+
requirements:
|
30
|
+
- - =
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.7.0
|
25
33
|
type: :development
|
26
|
-
version_requirements: *id001
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: yard
|
29
34
|
prerelease: false
|
30
|
-
|
35
|
+
version_requirements: *2157319020
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: yard
|
38
|
+
requirement: &2157318560 !ruby/object:Gem::Requirement
|
31
39
|
none: false
|
32
|
-
requirements:
|
33
|
-
- -
|
34
|
-
- !ruby/object:Gem::Version
|
35
|
-
version: 0.
|
40
|
+
requirements:
|
41
|
+
- - =
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.7.2
|
36
44
|
type: :development
|
37
|
-
version_requirements: *id002
|
38
|
-
- !ruby/object:Gem::Dependency
|
39
|
-
name: bluecloth
|
40
45
|
prerelease: false
|
41
|
-
|
46
|
+
version_requirements: *2157318560
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bluecloth
|
49
|
+
requirement: &2157318100 !ruby/object:Gem::Requirement
|
42
50
|
none: false
|
43
|
-
requirements:
|
44
|
-
- -
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: 2.
|
51
|
+
requirements:
|
52
|
+
- - =
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.2.0
|
47
55
|
type: :development
|
48
|
-
|
49
|
-
|
50
|
-
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2157318100
|
58
|
+
description: FS gathers the cluttered methods for working with files and dirs. Internally
|
59
|
+
using the good old standard library, but providing simple methods in a single place.
|
60
|
+
email:
|
51
61
|
- blindgaenger@gmail.com
|
52
62
|
executables: []
|
53
|
-
|
54
63
|
extensions: []
|
55
|
-
|
56
64
|
extra_rdoc_files: []
|
57
|
-
|
58
|
-
files:
|
65
|
+
files:
|
59
66
|
- .gitignore
|
67
|
+
- .rspec
|
60
68
|
- Gemfile
|
61
69
|
- README.mdown
|
62
70
|
- Rakefile
|
@@ -70,35 +78,37 @@ files:
|
|
70
78
|
- spec/spec_helper.rb
|
71
79
|
- spec/support/test_dir_support.rb
|
72
80
|
- spec/test_dir_spec.rb
|
73
|
-
has_rdoc: true
|
74
81
|
homepage: http://github.com/blindgaenger/fs
|
75
82
|
licenses: []
|
76
|
-
|
77
83
|
post_install_message:
|
78
84
|
rdoc_options: []
|
79
|
-
|
80
|
-
require_paths:
|
85
|
+
require_paths:
|
81
86
|
- lib
|
82
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
88
|
none: false
|
84
|
-
requirements:
|
85
|
-
- -
|
86
|
-
- !ruby/object:Gem::Version
|
87
|
-
version:
|
88
|
-
|
89
|
+
requirements:
|
90
|
+
- - ! '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
hash: 612170262386871478
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
97
|
none: false
|
90
|
-
requirements:
|
91
|
-
- -
|
92
|
-
- !ruby/object:Gem::Version
|
93
|
-
version:
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
hash: 612170262386871478
|
94
105
|
requirements: []
|
95
|
-
|
96
106
|
rubyforge_project:
|
97
|
-
rubygems_version: 1.
|
107
|
+
rubygems_version: 1.8.10
|
98
108
|
signing_key:
|
99
109
|
specification_version: 3
|
100
110
|
summary: Work with your filesystem!
|
101
|
-
test_files:
|
111
|
+
test_files:
|
102
112
|
- spec/alias_spec.rb
|
103
113
|
- spec/base_spec.rb
|
104
114
|
- spec/spec_helper.rb
|