fast 0.0.3 → 0.0.4
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/README.rdoc +8 -0
- data/lib/fast/dir.rb +143 -22
- data/lib/fast/file.rb +57 -3
- data/lib/fast/version.rb +1 -1
- data/lib/fast.rb +5 -1
- data/spec/fast/dir-filter_spec.rb +22 -0
- data/spec/fast/dir_spec.rb +228 -8
- data/spec/fast/file_spec.rb +131 -8
- metadata +17 -7
data/README.rdoc
CHANGED
@@ -20,8 +20,16 @@ Don't install right now, as 13-09-2011 this is pre-alpha, but in intensive devel
|
|
20
20
|
<tt>Fast::Dir</tt> is a subclass of <tt>Array</tt>, usable as a hash, and <tt>Fast::File</tt> if a subclass of String.
|
21
21
|
|
22
22
|
== Quick notes
|
23
|
+
* Move all Fast code to fast/main.rb. Update Metafun/Delegator so it will inject the #delegate method into every Object instance. Reduce the "fast.rb" to a call to external libraries, fast/main and DSLization via #delegate.
|
24
|
+
* Describe the SubSetter pattern for filtering.
|
23
25
|
* File lists as returned by Fast::Dir#list and Fast::Dir#dirs will be filtered after the list is retrieved by a set of filtering methods of the returned list, which should be an instance of Fast::Dir.
|
24
26
|
* An instance of Fast::Dir should be possible to be created from a Array.
|
27
|
+
* The path can be setted indirectly by any method of Fast::File instances, and the same works for Dir. This is fine because allows for very quick calls, but once an instance gets a path setted it should be fixed and raise an exception in case some other method call is trying to change it.
|
28
|
+
|
29
|
+
== Remote future
|
30
|
+
* Make Fast a REST client (well, use <tt>rest-client</tt>) in order to transparently use files and directories from a compliant REST server.
|
31
|
+
* Include REST methods: Dir#post, File#get, File#head, etc
|
32
|
+
* Allow Files to behave as Dirs with the right method calls
|
25
33
|
|
26
34
|
== License
|
27
35
|
|
data/lib/fast/dir.rb
CHANGED
@@ -46,41 +46,60 @@ module Fast
|
|
46
46
|
end
|
47
47
|
|
48
48
|
# Creates the dir, if it doesn't exist. Otherwise remains silent
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
unless ::File.directory? route.join "/"
|
56
|
-
::Dir.mkdir route.join "/"
|
57
|
-
end
|
49
|
+
# Returns the last dir path passed as argument
|
50
|
+
def create *args
|
51
|
+
if args.length > 0
|
52
|
+
return_me = nil
|
53
|
+
args.each do |path|
|
54
|
+
return_me = do_create path
|
58
55
|
end
|
59
|
-
|
60
|
-
|
56
|
+
return return_me
|
57
|
+
else
|
58
|
+
do_create
|
59
|
+
end
|
61
60
|
end
|
62
61
|
|
63
62
|
alias :create! :create
|
64
63
|
|
65
64
|
# Deletes the directory along with all its content. Powerful, simple, risky!
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
::File.unlink "#{@path}/#{entry}"
|
65
|
+
# Many arguments can be passed
|
66
|
+
def delete *args
|
67
|
+
if args.length > 0
|
68
|
+
return_me = nil
|
69
|
+
args.each do |path|
|
70
|
+
return_me = do_delete path
|
73
71
|
end
|
72
|
+
return return_me
|
73
|
+
else
|
74
|
+
do_delete
|
74
75
|
end
|
75
|
-
::Dir.unlink @path
|
76
|
-
@path
|
77
76
|
end
|
78
77
|
|
79
|
-
alias :delete! :delete
|
80
78
|
alias :destroy :delete
|
81
79
|
alias :del :delete
|
82
80
|
alias :unlink :delete
|
83
81
|
|
82
|
+
# Like #delete, but raises no error if some directory is missing
|
83
|
+
def delete! *args
|
84
|
+
if args.length > 0
|
85
|
+
return_me = nil
|
86
|
+
args.each do |path|
|
87
|
+
begin
|
88
|
+
return_me = do_delete path
|
89
|
+
rescue
|
90
|
+
return_me = nil
|
91
|
+
end
|
92
|
+
end
|
93
|
+
return return_me
|
94
|
+
else
|
95
|
+
begin
|
96
|
+
do_delete
|
97
|
+
rescue
|
98
|
+
nil
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
84
103
|
# Checks for existence. True if the directory exists, false otherwise
|
85
104
|
def exist? path = nil
|
86
105
|
@path = normalize path if path
|
@@ -109,9 +128,111 @@ module Fast
|
|
109
128
|
|
110
129
|
alias :absolute :expand
|
111
130
|
|
131
|
+
# Returns the path to the dir, if defined
|
132
|
+
def path
|
133
|
+
@path if @path
|
134
|
+
end
|
135
|
+
|
136
|
+
# Renames this dir into the target path, unless the target path
|
137
|
+
# points to an existing dir.
|
138
|
+
def rename *args
|
139
|
+
if args.length > 1
|
140
|
+
current, target = *args
|
141
|
+
@path = normalize current
|
142
|
+
target = normalize target
|
143
|
+
else
|
144
|
+
target = normalize args.first
|
145
|
+
end
|
146
|
+
|
147
|
+
raise ArgumentError, "The target directory '#{target}' already exists" if Dir.new.exist? target
|
148
|
+
do_rename_to target
|
149
|
+
end
|
150
|
+
|
151
|
+
# Renames this dir into the target path: overwrites the target dir
|
152
|
+
# if it exists
|
153
|
+
def rename! *args
|
154
|
+
if args.length > 1
|
155
|
+
current, target = *args
|
156
|
+
@path = normalize current
|
157
|
+
target = normalize target
|
158
|
+
else
|
159
|
+
target = normalize args.first
|
160
|
+
end
|
161
|
+
Dir.new.delete! target if Dir.new.exist? target
|
162
|
+
do_rename_to target
|
163
|
+
end
|
164
|
+
|
165
|
+
# Merges the target dir into this
|
166
|
+
def merge *args
|
167
|
+
if args.length > 1
|
168
|
+
current, target = *args
|
169
|
+
@path = normalize current
|
170
|
+
target = normalize target
|
171
|
+
else
|
172
|
+
target = normalize args.first
|
173
|
+
end
|
174
|
+
|
175
|
+
Dir.new.list target do |entry|
|
176
|
+
unless Dir.new.exist? "#{target}/#{entry}"
|
177
|
+
File.new.rename "#{target}/#{entry}", "#{@path}/#{entry}"
|
178
|
+
else
|
179
|
+
Dir.new.rename "#{target}/#{entry}", "#{@path}/#{entry}"
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
Dir.new.delete target
|
184
|
+
end
|
185
|
+
|
112
186
|
private
|
187
|
+
def do_delete path = nil
|
188
|
+
@path = normalize path if path
|
189
|
+
Dir.new.list @path do |entry|
|
190
|
+
if ::File.directory? "#{@path}/#{entry}"
|
191
|
+
Dir.new.delete "#{@path}/#{entry}"
|
192
|
+
else
|
193
|
+
::File.unlink "#{@path}/#{entry}"
|
194
|
+
end
|
195
|
+
end
|
196
|
+
::Dir.unlink @path
|
197
|
+
@path
|
198
|
+
end
|
199
|
+
|
200
|
+
def do_create path = nil
|
201
|
+
@path = normalize path if path
|
202
|
+
route = []
|
203
|
+
@path.split("/").each do |part|
|
204
|
+
unless part.empty?
|
205
|
+
route << part
|
206
|
+
unless ::File.directory? route.join "/"
|
207
|
+
::Dir.mkdir route.join "/"
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end unless ::File.directory? @path
|
211
|
+
self
|
212
|
+
end
|
213
|
+
|
214
|
+
def do_rename_to target
|
215
|
+
# 1. Create the target dir
|
216
|
+
target_dir = Dir.new.create! target
|
217
|
+
|
218
|
+
# 2. Move all files
|
219
|
+
files do |file|
|
220
|
+
File.new.rename "#{@path}/#{file}", "#{target_dir}/#{file}"
|
221
|
+
end
|
222
|
+
|
223
|
+
# 3. Rename recursively all dirs
|
224
|
+
dirs do |dir|
|
225
|
+
Dir.new.rename "#{@path}/#{dir}", "#{target_dir}/#{dir}"
|
226
|
+
end
|
227
|
+
|
228
|
+
# 4. Delete current dir
|
229
|
+
self.delete!
|
230
|
+
|
231
|
+
target_dir
|
232
|
+
end
|
233
|
+
|
113
234
|
def normalize path
|
114
|
-
|
235
|
+
"#{path}"
|
115
236
|
end
|
116
237
|
end
|
117
238
|
end
|
data/lib/fast/file.rb
CHANGED
@@ -5,7 +5,8 @@ module Fast
|
|
5
5
|
# Initializes the file
|
6
6
|
def initialize source = nil
|
7
7
|
unless source.nil?
|
8
|
-
super( "#{source}" )
|
8
|
+
super( "#{source}" )
|
9
|
+
@path = normalize source
|
9
10
|
else
|
10
11
|
super()
|
11
12
|
end
|
@@ -25,7 +26,23 @@ module Fast
|
|
25
26
|
::File.open @path, "a" do |handler|
|
26
27
|
handler.write content
|
27
28
|
end
|
28
|
-
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
# Writes data into the file. If is does not exist, creates it
|
33
|
+
# if it already exists, overwrites it!
|
34
|
+
def write *args
|
35
|
+
if args.length > 1
|
36
|
+
path, content = *args
|
37
|
+
@path = normalize path
|
38
|
+
else
|
39
|
+
content = args.first
|
40
|
+
end
|
41
|
+
Fast.dir! ::File.dirname @path if ::File.dirname(@path) != "."
|
42
|
+
::File.open @path, "w" do |handler|
|
43
|
+
handler.write content
|
44
|
+
end
|
45
|
+
self
|
29
46
|
end
|
30
47
|
|
31
48
|
# Deletes the file (wrapper for `File.unlink <path>`)
|
@@ -55,7 +72,7 @@ module Fast
|
|
55
72
|
alias :create! :touch
|
56
73
|
|
57
74
|
# Returns the contents of the file, all at once
|
58
|
-
def read path
|
75
|
+
def read path = nil
|
59
76
|
@path = normalize path if path
|
60
77
|
::File.read @path
|
61
78
|
end
|
@@ -67,6 +84,8 @@ module Fast
|
|
67
84
|
end
|
68
85
|
|
69
86
|
alias :exists? :exist?
|
87
|
+
alias :exist_all? :exist?
|
88
|
+
alias :exist_any? :exist?
|
70
89
|
|
71
90
|
# Sends self to a FileFilter filter
|
72
91
|
def filter
|
@@ -83,6 +102,41 @@ module Fast
|
|
83
102
|
|
84
103
|
alias :absolute :expand
|
85
104
|
|
105
|
+
# Renames the file (by Fast::File own means, it does not call
|
106
|
+
# the underlying OS). Fails if the new path is an existent file
|
107
|
+
def rename *args
|
108
|
+
if args.length > 1
|
109
|
+
path, new_path = *args
|
110
|
+
@path = normalize path
|
111
|
+
new_path = normalize new_path
|
112
|
+
else
|
113
|
+
new_path = normalize args.first
|
114
|
+
end
|
115
|
+
raise ArgumentError, "The file '#{new_path}' already exists" if File.new.exists? new_path
|
116
|
+
renamed = File.new.write new_path, self.read
|
117
|
+
self.delete!
|
118
|
+
return renamed
|
119
|
+
end
|
120
|
+
|
121
|
+
# Like #rename, but overwrites the new file if is exist
|
122
|
+
def rename! *args
|
123
|
+
if args.length > 1
|
124
|
+
path, new_path = *args
|
125
|
+
@path = normalize path
|
126
|
+
new_path = normalize new_path
|
127
|
+
else
|
128
|
+
new_path = normalize args.first
|
129
|
+
end
|
130
|
+
renamed = File.new.write new_path, self.read
|
131
|
+
self.delete!
|
132
|
+
return renamed
|
133
|
+
end
|
134
|
+
|
135
|
+
# Returns the path to the current file
|
136
|
+
def path
|
137
|
+
@path if @path
|
138
|
+
end
|
139
|
+
|
86
140
|
private
|
87
141
|
def normalize path
|
88
142
|
"#{path}"
|
data/lib/fast/version.rb
CHANGED
data/lib/fast.rb
CHANGED
@@ -50,6 +50,10 @@ module Fast
|
|
50
50
|
File.new.exist? path
|
51
51
|
end
|
52
52
|
|
53
|
+
def self.file! path
|
54
|
+
File.new.touch path
|
55
|
+
end
|
56
|
+
|
53
57
|
# Returns an instance of Fast::File and passed all methods
|
54
58
|
# and arguments to it
|
55
59
|
def self.file *args
|
@@ -59,4 +63,4 @@ end
|
|
59
63
|
|
60
64
|
include Metafun::Delegator
|
61
65
|
|
62
|
-
delegate Fast, :dir, :dir?, :dir!, :file, :file
|
66
|
+
delegate Fast, :dir, :dir?, :dir!, :file, :file?, :file!
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "fast"
|
2
|
+
require "zucker/os"
|
3
|
+
|
4
|
+
describe Fast::DirFilter do
|
5
|
+
describe "#extension" do
|
6
|
+
context "when given a list of file names and a extension" do
|
7
|
+
it "should return a list of the files with the given extension"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
# VERY IMPORTANT: DirFilter should extend a class ListFilter
|
12
|
+
# #match implementation (along with a short list of other things) should
|
13
|
+
# be done in ListFilter, not in DirFilter
|
14
|
+
#
|
15
|
+
# The SubSetter pattern is still not defined nor implemented: I'll start by
|
16
|
+
# finishing Fast and after that I'll dig deeper into SubSetting
|
17
|
+
describe "#match" do
|
18
|
+
context "when given a list of strings and a regexp" do
|
19
|
+
it "should return a list containing the strings that match the expression"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/spec/fast/dir_spec.rb
CHANGED
@@ -149,6 +149,22 @@ describe Fast::Dir do
|
|
149
149
|
::Dir.unlink "demo"
|
150
150
|
end
|
151
151
|
end
|
152
|
+
|
153
|
+
it "should work with several arguments" do
|
154
|
+
Fast::Dir.new.should_not exist :demo
|
155
|
+
Fast::Dir.new.should_not exist :alt
|
156
|
+
Fast::Dir.new.should_not exist :other
|
157
|
+
|
158
|
+
Fast::Dir.new.send @method, :demo, :alt, :other
|
159
|
+
|
160
|
+
Fast::Dir.new.should exist :demo
|
161
|
+
Fast::Dir.new.should exist :alt
|
162
|
+
Fast::Dir.new.should exist :other
|
163
|
+
|
164
|
+
Fast::Dir.new.delete! :demo
|
165
|
+
Fast::Dir.new.delete! :alt
|
166
|
+
Fast::Dir.new.delete! :other
|
167
|
+
end
|
152
168
|
end
|
153
169
|
|
154
170
|
describe "#create" do
|
@@ -191,13 +207,7 @@ describe Fast::Dir do
|
|
191
207
|
end
|
192
208
|
|
193
209
|
|
194
|
-
shared_examples_for "any dir deletion" do
|
195
|
-
it "should fail if the directory does not exist" do
|
196
|
-
::File.should_not be_directory "demo"
|
197
|
-
expect { Fast::Dir.new.send @method, "demo"
|
198
|
-
}.to raise_error
|
199
|
-
end
|
200
|
-
|
210
|
+
shared_examples_for "any dir deletion" do
|
201
211
|
it "should delete the directory if it exists" do
|
202
212
|
::File.should_not be_directory "demo"
|
203
213
|
Fast::Dir.new.create "demo"
|
@@ -227,31 +237,71 @@ describe Fast::Dir do
|
|
227
237
|
Fast::Dir.new.create "demo"
|
228
238
|
Fast::Dir.new.send( @method, "demo" ).should == "demo"
|
229
239
|
end
|
240
|
+
|
241
|
+
it "should work with several arguments" do
|
242
|
+
Fast::Dir.new.should_not exist :demo
|
243
|
+
Fast::Dir.new.should_not exist :alt
|
244
|
+
Fast::Dir.new.should_not exist :other
|
245
|
+
|
246
|
+
Fast::Dir.new.create! :demo, :alt, :other
|
247
|
+
Fast::Dir.new.send @method, :demo, :alt, :other
|
248
|
+
|
249
|
+
Fast::Dir.new.should_not exist :demo
|
250
|
+
Fast::Dir.new.should_not exist :alt
|
251
|
+
Fast::Dir.new.should_not exist :other
|
252
|
+
end
|
230
253
|
end
|
231
254
|
|
232
255
|
describe "#delete" do
|
233
256
|
before :each do @method = :delete end
|
234
257
|
it_behaves_like "any dir deletion"
|
258
|
+
|
259
|
+
it "should fail if the directory does not exist" do
|
260
|
+
::File.should_not be_directory "demo"
|
261
|
+
expect { Fast::Dir.new.send @method, "demo"
|
262
|
+
}.to raise_error
|
263
|
+
end
|
235
264
|
end
|
236
265
|
|
237
266
|
describe "#delete!" do
|
238
267
|
before :each do @method = :delete! end
|
239
268
|
it_behaves_like "any dir deletion"
|
269
|
+
|
270
|
+
it "should not fail even if the directory does not exist" do
|
271
|
+
Fast::Dir.new.should_not exist :demo
|
272
|
+
Fast::Dir.new.delete! :demo
|
273
|
+
end
|
240
274
|
end
|
241
275
|
|
242
276
|
describe "#del" do
|
243
277
|
before :each do @method = :del end
|
244
278
|
it_behaves_like "any dir deletion"
|
279
|
+
it "should fail if the directory does not exist" do
|
280
|
+
::File.should_not be_directory "demo"
|
281
|
+
expect { Fast::Dir.new.send @method, "demo"
|
282
|
+
}.to raise_error
|
283
|
+
end
|
245
284
|
end
|
246
285
|
|
247
286
|
describe "#destroy" do
|
248
287
|
before :each do @method = :destroy end
|
249
288
|
it_behaves_like "any dir deletion"
|
289
|
+
it "should fail if the directory does not exist" do
|
290
|
+
::File.should_not be_directory "demo"
|
291
|
+
expect { Fast::Dir.new.send @method, "demo"
|
292
|
+
}.to raise_error
|
293
|
+
end
|
250
294
|
end
|
251
295
|
|
252
296
|
describe "#unlink" do
|
253
297
|
before :each do @method = :unlink end
|
254
298
|
it_behaves_like "any dir deletion"
|
299
|
+
|
300
|
+
it "should fail if the directory does not exist" do
|
301
|
+
::File.should_not be_directory "demo"
|
302
|
+
expect { Fast::Dir.new.send @method, "demo"
|
303
|
+
}.to raise_error
|
304
|
+
end
|
255
305
|
end
|
256
306
|
|
257
307
|
shared_examples_for "any dir existencialism" do
|
@@ -323,10 +373,180 @@ describe Fast::Dir do
|
|
323
373
|
it_behaves_like "any dir absolutizer"
|
324
374
|
end
|
325
375
|
|
376
|
+
describe "#path" do
|
377
|
+
context "the path is setted" do
|
378
|
+
it "should return the path" do
|
379
|
+
the_dir = Fast::Dir.new "demo"
|
380
|
+
the_dir.path.should == "demo"
|
381
|
+
end
|
382
|
+
end
|
383
|
+
|
384
|
+
context "the path is undefined" do
|
385
|
+
it "should return nil" do
|
386
|
+
the_dir = Fast::Dir.new
|
387
|
+
the_dir.path.should be_nil
|
388
|
+
end
|
389
|
+
end
|
390
|
+
end
|
391
|
+
|
392
|
+
shared_examples_for "any dir renaming" do
|
393
|
+
it "should delete current dir and target dir should exist" do
|
394
|
+
Fast::Dir.new.should_not exist "demo"
|
395
|
+
Fast::Dir.new.should_not exist "renamed"
|
396
|
+
Fast::Dir.new.create! "demo"
|
397
|
+
Fast::Dir.new.send @method, "demo", "renamed"
|
398
|
+
Fast::Dir.new.should_not exist "demo"
|
399
|
+
Fast::Dir.new.should exist "renamed"
|
400
|
+
Fast::Dir.new.delete! "renamed"
|
401
|
+
end
|
402
|
+
|
403
|
+
it "should return a dir with the new dirs name" do
|
404
|
+
Fast::Dir.new.should_not exist "demo"
|
405
|
+
Fast::Dir.new.should_not exist "renamed"
|
406
|
+
Fast::Dir.new.create! "demo"
|
407
|
+
Fast::Dir.new.send( @method, "demo", "renamed" ).path.should == "renamed"
|
408
|
+
Fast::Dir.new.delete! "renamed"
|
409
|
+
end
|
410
|
+
|
411
|
+
it "should contain the same data the target as the source" do
|
412
|
+
Fast::Dir.new.should_not exist "demo"
|
413
|
+
Fast::Dir.new.should_not exist "renamed"
|
414
|
+
Fast::File.new.touch "demo/content.file"
|
415
|
+
Fast::File.new.touch "demo/in/subdir/more.content"
|
416
|
+
Fast::File.new.touch "demo/hope.txt"
|
417
|
+
|
418
|
+
Fast::Dir.new.send @method, "demo", :renamed # Yeah, symbols work too
|
419
|
+
Fast::Dir.new.should_not exist :demo
|
420
|
+
Fast::File.new.should exist "renamed/content.file"
|
421
|
+
Fast::File.new.should exist "renamed/hope.txt"
|
422
|
+
Fast::File.new.should exist "renamed/in/subdir/more.content"
|
423
|
+
|
424
|
+
Fast::Dir.new.delete! :renamed
|
425
|
+
end
|
426
|
+
end
|
427
|
+
|
326
428
|
describe "#rename" do
|
327
|
-
|
429
|
+
before :all do @method = :rename end
|
430
|
+
it_behaves_like "any dir renaming"
|
431
|
+
|
432
|
+
it "should fail if the new path represents an existing dir" do
|
433
|
+
Fast::Dir.new.should_not exist :demo
|
434
|
+
Fast::Dir.new.should_not exist :renamed
|
435
|
+
Fast::Dir.new.create! :demo
|
436
|
+
Fast::Dir.new.create! :renamed
|
437
|
+
expect { Fast::Dir.new.rename :demo, :renamed
|
438
|
+
}.to raise_error ArgumentError, "The target directory 'renamed' already exists"
|
439
|
+
Fast::Dir.new.delete! :demo
|
440
|
+
Fast::Dir.new.delete! :renamed
|
441
|
+
end
|
442
|
+
end
|
443
|
+
|
444
|
+
describe "#rename!" do
|
445
|
+
before :all do @method = :rename! end
|
446
|
+
it_behaves_like "any dir renaming"
|
447
|
+
|
448
|
+
it "should overwrite the dir at the new path if it exists" do
|
449
|
+
Fast::Dir.new.should_not exist :demo
|
450
|
+
Fast::Dir.new.should_not exist :renamed
|
451
|
+
Fast::File.new.touch "demo/content.file"
|
452
|
+
Fast::File.new.touch "renamed/erase.me"
|
453
|
+
|
454
|
+
Fast::Dir.new.rename! :demo, :renamed
|
455
|
+
Fast::File.new.should_not exist "renamed/erase.me"
|
456
|
+
Fast::File.new.should exist "renamed/content.file"
|
457
|
+
Fast::Dir.new.delete! :renamed
|
458
|
+
end
|
459
|
+
end
|
460
|
+
|
461
|
+
shared_examples_for "any dir copy" do
|
462
|
+
context "target dir do not exist" do
|
463
|
+
it "should create the target dir"
|
464
|
+
|
465
|
+
it "should not erase current dir"
|
466
|
+
end
|
467
|
+
|
468
|
+
it "should be present all of source data in the target"
|
469
|
+
|
470
|
+
it "should return current dir"
|
471
|
+
end
|
472
|
+
|
473
|
+
describe "#copy" do
|
474
|
+
it_behaves_like "any dir copy"
|
475
|
+
|
476
|
+
it "should fail if any conflict appears"
|
477
|
+
end
|
478
|
+
|
479
|
+
describe "#copy!" do
|
480
|
+
it_behaves_like "any dir copy"
|
481
|
+
|
482
|
+
it "should overwrite in every conflict"
|
483
|
+
end
|
484
|
+
|
485
|
+
describe "#merge" do
|
486
|
+
before :each do
|
487
|
+
Fast::Dir.new.should_not exist :demo
|
488
|
+
Fast::Dir.new.should_not exist :mergeme
|
489
|
+
end
|
490
|
+
|
491
|
+
it "should delete target dir" do
|
492
|
+
Fast::File.new.touch "demo/content.file"
|
493
|
+
Fast::File.new.touch "mergeme/mergeable.file"
|
494
|
+
|
495
|
+
Fast::Dir.new.merge :demo, :mergeme
|
496
|
+
Fast::Dir.new.should_not exist :mergeme
|
497
|
+
end
|
498
|
+
|
499
|
+
it "should fail if target dir does not exist" do
|
500
|
+
Fast::Dir.new.create! :demo
|
501
|
+
expect { Fast::Dir.new.merge :demo, :mergeme
|
502
|
+
}.to raise_error Errno::ENOENT
|
503
|
+
end
|
504
|
+
|
505
|
+
it "should put contents of target dir into current dir, recursively" do
|
506
|
+
Fast::File.new.touch "demo/content.file"
|
507
|
+
Fast::File.new.touch "demo/more.file"
|
508
|
+
Fast::File.new.touch "mergeme/data/info.file"
|
509
|
+
Fast::File.new.touch "mergeme/info.rb"
|
510
|
+
Fast::File.new.touch "mergeme/data/nested/is.informative.file"
|
511
|
+
|
512
|
+
Fast::Dir.new.merge :demo, :mergeme
|
513
|
+
Fast::Dir.new.should_not exist :mergeme
|
514
|
+
|
515
|
+
Fast::File.new.should exist "demo/content.file"
|
516
|
+
Fast::File.new.should exist "demo/more.file"
|
517
|
+
Fast::File.new.should exist "demo/data/info.file"
|
518
|
+
Fast::File.new.should exist "demo/info.rb"
|
519
|
+
Fast::File.new.should exist "demo/data/nested/is.informative.file"
|
520
|
+
end
|
521
|
+
|
522
|
+
context "two fails in the source and target have the same name" do
|
523
|
+
it "should fail"
|
524
|
+
|
525
|
+
it "should not do any changes in any dir"
|
526
|
+
end
|
527
|
+
|
528
|
+
after :each do
|
529
|
+
Fast::Dir.new.delete! :demo if Fast::Dir.new.exist? :demo
|
530
|
+
Fast::Dir.new.delete! :mergeme if Fast::Dir.new.exist? :mergeme
|
531
|
+
end
|
532
|
+
end
|
533
|
+
|
534
|
+
describe "#merge!" do
|
535
|
+
it "should behave like #merge but never fail"
|
328
536
|
end
|
329
537
|
|
538
|
+
describe "#mergeable?" do
|
539
|
+
context "both dirs exist and no file or dir in any has the same name in the other" do
|
540
|
+
it "should return true"
|
541
|
+
end
|
542
|
+
|
543
|
+
context "some files in target dir have the same name as other in source" do
|
544
|
+
it "should return false"
|
545
|
+
end
|
546
|
+
|
547
|
+
it "should fail it the target dir does not exist"
|
548
|
+
end
|
549
|
+
|
330
550
|
describe "#[]" do
|
331
551
|
context "a file named like the argument exists" do
|
332
552
|
it "should return it"
|
data/spec/fast/file_spec.rb
CHANGED
@@ -47,7 +47,11 @@ describe Fast::File do
|
|
47
47
|
::File.unlink "demo.txt"
|
48
48
|
end
|
49
49
|
|
50
|
-
it "should return the file"
|
50
|
+
it "should return the file" do
|
51
|
+
the_file = ::Fast::File.new.append "demo.file", "Some content."
|
52
|
+
the_file.should be_a Fast::File
|
53
|
+
the_file.delete!
|
54
|
+
end
|
51
55
|
|
52
56
|
it "should work even when a symbol is passed as argument" do
|
53
57
|
Fast::File.new.append :demo_txt, "Hola."
|
@@ -66,14 +70,42 @@ describe Fast::File do
|
|
66
70
|
end
|
67
71
|
end
|
68
72
|
|
73
|
+
describe "#<<" do
|
74
|
+
it "should behave almost like #append"
|
75
|
+
end
|
76
|
+
|
69
77
|
describe "#write" do
|
70
|
-
it "should create the file if it does not exist"
|
78
|
+
it "should create the file if it does not exist" do
|
79
|
+
Fast::File.new.should_not exist "demo.file"
|
80
|
+
Fast::File.new.write "demo.file", "This is all."
|
81
|
+
Fast::File.new.should exist "demo.file"
|
82
|
+
Fast::File.new.destroy "demo.file"
|
83
|
+
end
|
71
84
|
|
72
|
-
it "should write the given content into the file"
|
85
|
+
it "should write the given content into the file" do
|
86
|
+
Fast::File.new.should_not exist "demo.file"
|
87
|
+
the_file = Fast::File.new "demo.file"
|
88
|
+
the_file.write "This is content!"
|
89
|
+
the_file.read.should == "This is content!"
|
90
|
+
the_file.destroy
|
91
|
+
end
|
73
92
|
|
74
|
-
it "should overwrite the file if it exists"
|
93
|
+
it "should overwrite the file if it exists" do
|
94
|
+
Fast::File.new.should_not exist "demo.file"
|
95
|
+
::File.open "demo.file", "w" do |file|
|
96
|
+
file.write "Something..."
|
97
|
+
end
|
98
|
+
|
99
|
+
Fast::File.new.write "demo.file", "Another something"
|
100
|
+
Fast::File.new.read( "demo.file" ).should == "Another something"
|
101
|
+
Fast::File.new.delete! "demo.file"
|
102
|
+
end
|
75
103
|
|
76
|
-
it "should return the file"
|
104
|
+
it "should return the file" do
|
105
|
+
the_file = Fast::File.new.write "demo.file", "More content this time."
|
106
|
+
the_file.should be_a Fast::File
|
107
|
+
the_file.delete!
|
108
|
+
end
|
77
109
|
end
|
78
110
|
|
79
111
|
shared_examples_for "any file deletion" do
|
@@ -196,6 +228,8 @@ describe Fast::File do
|
|
196
228
|
Fast::File.new.send @method, :demo_txt
|
197
229
|
::File.unlink "demo_txt"
|
198
230
|
end
|
231
|
+
|
232
|
+
it "should work with multiple arguments"
|
199
233
|
end
|
200
234
|
|
201
235
|
describe "#create" do
|
@@ -255,7 +289,7 @@ describe Fast::File do
|
|
255
289
|
end
|
256
290
|
|
257
291
|
context "a block is passed" do
|
258
|
-
it "should
|
292
|
+
it "should have direct access to file's methods"
|
259
293
|
end
|
260
294
|
end
|
261
295
|
|
@@ -280,6 +314,8 @@ describe Fast::File do
|
|
280
314
|
::File.should_not exist "demo.file"
|
281
315
|
Fast::File.new.send( @method, "demo.file" ).should be_false
|
282
316
|
end
|
317
|
+
|
318
|
+
it "should return false if path represents a directory!"
|
283
319
|
end
|
284
320
|
|
285
321
|
describe "#exist?" do
|
@@ -292,6 +328,24 @@ describe Fast::File do
|
|
292
328
|
it_behaves_like "any file existencialism"
|
293
329
|
end
|
294
330
|
|
331
|
+
describe "#exist_all?" do
|
332
|
+
before :each do @method = :exist_all? end
|
333
|
+
it_behaves_like "any file existencialism"
|
334
|
+
|
335
|
+
it "should return true if all exist"
|
336
|
+
|
337
|
+
it "should return false if any does not exist"
|
338
|
+
end
|
339
|
+
|
340
|
+
describe "#exist_any?" do
|
341
|
+
before :each do @method = :exist_any? end
|
342
|
+
it_behaves_like "any file existencialism"
|
343
|
+
|
344
|
+
it "should return true if at least one exists"
|
345
|
+
|
346
|
+
it "should return false if none exist"
|
347
|
+
end
|
348
|
+
|
295
349
|
shared_examples_for "any file subsetter" do
|
296
350
|
# This is a reminder: along with Serializer, the Subsetter pattern
|
297
351
|
# (and later, the Sorting one) should be implemented Fast
|
@@ -351,8 +405,77 @@ describe Fast::File do
|
|
351
405
|
before :each do @method = :absolute end
|
352
406
|
it_behaves_like "any file absolutizer"
|
353
407
|
end
|
354
|
-
|
408
|
+
|
409
|
+
describe "#path" do
|
410
|
+
context "the path is setted" do
|
411
|
+
it "returns the path" do
|
412
|
+
the_file = Fast::File.new "demo.file"
|
413
|
+
the_file.path.should == "demo.file"
|
414
|
+
end
|
415
|
+
end
|
416
|
+
|
417
|
+
context "the path is undefined" do
|
418
|
+
it "returns nil" do
|
419
|
+
the_file = Fast::File.new
|
420
|
+
the_file.path.should be_nil
|
421
|
+
end
|
422
|
+
end
|
423
|
+
end
|
424
|
+
|
425
|
+
shared_examples_for "any file renaming" do
|
426
|
+
it "should change the file's name" do
|
427
|
+
Fast::File.new.should_not exist "demo.file"
|
428
|
+
Fast::File.new.should_not exist "renamed.file"
|
429
|
+
Fast::File.new.write "demo.file", "This content is the proof."
|
430
|
+
Fast::File.new.send @method, "demo.file", "renamed.file"
|
431
|
+
|
432
|
+
Fast::File.new.should_not exist "demo.file"
|
433
|
+
Fast::File.new.should exist "renamed.file"
|
434
|
+
Fast::File.new.read( "renamed.file" ).should == "This content is the proof."
|
435
|
+
Fast::File.new.delete! "renamed.file"
|
436
|
+
end
|
437
|
+
end
|
438
|
+
|
355
439
|
describe "#rename" do
|
356
|
-
|
440
|
+
before :all do @method = :rename end
|
441
|
+
it_behaves_like "any file renaming"
|
442
|
+
|
443
|
+
it "should fail if a file named as the new name exists" do
|
444
|
+
Fast::File.new.should_not exist "demo.file"
|
445
|
+
Fast::File.new.should_not exist "renamed.file"
|
446
|
+
Fast::File.new.touch "renamed.file"
|
447
|
+
Fast::File.new.write "demo.file", "Demo content bores me"
|
448
|
+
|
449
|
+
expect { Fast::File.new.rename "demo.file", "renamed.file"
|
450
|
+
}.to raise_error ArgumentError, "The file 'renamed.file' already exists"
|
451
|
+
|
452
|
+
Fast::File.new.delete! "demo.file"
|
453
|
+
Fast::File.new.delete! "renamed.file"
|
454
|
+
end
|
455
|
+
end
|
456
|
+
|
457
|
+
describe "#rename!" do
|
458
|
+
before :all do @method = :rename! end
|
459
|
+
it_behaves_like "any file renaming"
|
460
|
+
|
461
|
+
it "should overwrite the new file if it exists" do
|
462
|
+
Fast::File.new.should_not exist "demo.file"
|
463
|
+
Fast::File.new.should_not exist "renamed.file"
|
464
|
+
Fast::File.new.touch "renamed.file"
|
465
|
+
Fast::File.new.write "demo.file", "Demo content bores me"
|
466
|
+
|
467
|
+
Fast::File.new.rename! "demo.file", "renamed.file"
|
468
|
+
|
469
|
+
Fast::File.new.should_not exist "demo.file"
|
470
|
+
Fast::File.new.read( "renamed.file" ).should == "Demo content bores me"
|
471
|
+
|
472
|
+
Fast::File.new.delete! "renamed.file"
|
473
|
+
end
|
474
|
+
end
|
475
|
+
|
476
|
+
describe "#merge" do
|
477
|
+
it "should delete the target file"
|
478
|
+
|
479
|
+
it "should append the contents of the target into this"
|
357
480
|
end
|
358
481
|
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fast
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Xavier Via
|
@@ -14,16 +15,17 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2011-11-
|
18
|
-
default_executable:
|
18
|
+
date: 2011-11-14 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: metafun
|
22
22
|
prerelease: false
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
24
25
|
requirements:
|
25
26
|
- - ">="
|
26
27
|
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
27
29
|
segments:
|
28
30
|
- 0
|
29
31
|
version: "0"
|
@@ -33,9 +35,11 @@ dependencies:
|
|
33
35
|
name: rspec
|
34
36
|
prerelease: false
|
35
37
|
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
36
39
|
requirements:
|
37
40
|
- - ">="
|
38
41
|
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
39
43
|
segments:
|
40
44
|
- 0
|
41
45
|
version: "0"
|
@@ -45,9 +49,11 @@ dependencies:
|
|
45
49
|
name: zucker
|
46
50
|
prerelease: false
|
47
51
|
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
48
53
|
requirements:
|
49
54
|
- - ">="
|
50
55
|
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
51
57
|
segments:
|
52
58
|
- 0
|
53
59
|
version: "0"
|
@@ -74,9 +80,9 @@ files:
|
|
74
80
|
- lib/fast/file-filter.rb
|
75
81
|
- lib/fast/file.rb
|
76
82
|
- lib/fast/version.rb
|
83
|
+
- spec/fast/dir-filter_spec.rb
|
77
84
|
- spec/fast/dir_spec.rb
|
78
85
|
- spec/fast/file_spec.rb
|
79
|
-
has_rdoc: true
|
80
86
|
homepage: ""
|
81
87
|
licenses: []
|
82
88
|
|
@@ -86,23 +92,27 @@ rdoc_options: []
|
|
86
92
|
require_paths:
|
87
93
|
- lib
|
88
94
|
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
89
96
|
requirements:
|
90
97
|
- - ">="
|
91
98
|
- !ruby/object:Gem::Version
|
99
|
+
hash: 3
|
92
100
|
segments:
|
93
101
|
- 0
|
94
102
|
version: "0"
|
95
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
96
105
|
requirements:
|
97
106
|
- - ">="
|
98
107
|
- !ruby/object:Gem::Version
|
108
|
+
hash: 3
|
99
109
|
segments:
|
100
110
|
- 0
|
101
111
|
version: "0"
|
102
112
|
requirements: []
|
103
113
|
|
104
114
|
rubyforge_project: fast
|
105
|
-
rubygems_version: 1.
|
115
|
+
rubygems_version: 1.8.11
|
106
116
|
signing_key:
|
107
117
|
specification_version: 3
|
108
118
|
summary: DSL for file system interaction
|