epitools 0.4.36 → 0.4.37
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/VERSION +1 -1
- data/epitools.gemspec +2 -2
- data/lib/epitools/autoloads.rb +1 -0
- data/lib/epitools/path.rb +60 -22
- data/spec/path_spec.rb +31 -4
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.37
|
data/epitools.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{epitools}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.37"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["epitron"]
|
12
|
-
s.date = %q{2011-05-
|
12
|
+
s.date = %q{2011-05-29}
|
13
13
|
s.description = %q{Miscellaneous utility libraries to make my life easier.}
|
14
14
|
s.email = %q{chris@ill-logic.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/epitools/autoloads.rb
CHANGED
data/lib/epitools/path.rb
CHANGED
@@ -52,6 +52,11 @@ class Path
|
|
52
52
|
def self.ls(path); Path[path].ls end
|
53
53
|
|
54
54
|
def self.ls_r(path); Path[path].ls_r; end
|
55
|
+
|
56
|
+
## TODO: Verbose mode
|
57
|
+
#def self.verbose=(value); @@verbose = value; end
|
58
|
+
#def self.verbose; @@verbose ||= false; end
|
59
|
+
|
55
60
|
|
56
61
|
## setters
|
57
62
|
|
@@ -302,26 +307,28 @@ class Path
|
|
302
307
|
def rename_to(path)
|
303
308
|
rename :path=>path
|
304
309
|
end
|
305
|
-
alias_method :
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
+
alias_method :mv, :rename_to
|
311
|
+
|
312
|
+
{
|
313
|
+
:mkdir => "Dir.mkdir",
|
314
|
+
:mkdir_p =>"FileUtils.mkdir_p"
|
315
|
+
}.each do |method, expression|
|
316
|
+
class_eval %{
|
317
|
+
def #{method}
|
318
|
+
if exists?
|
319
|
+
if directory?
|
320
|
+
false
|
321
|
+
else
|
322
|
+
raise "Error: Tried to make a directory over top of an existing file."
|
323
|
+
end
|
324
|
+
else
|
325
|
+
#{expression}(path)
|
326
|
+
true
|
327
|
+
end
|
328
|
+
end
|
329
|
+
}
|
310
330
|
end
|
311
|
-
alias_method :"unlink!", :"delete!"
|
312
331
|
|
313
|
-
def mkdir
|
314
|
-
|
315
|
-
end
|
316
|
-
|
317
|
-
def mkdir_p
|
318
|
-
if exists?
|
319
|
-
raise "Error: Path already exists."
|
320
|
-
else
|
321
|
-
FileUtils.mkdir_p(path)
|
322
|
-
end
|
323
|
-
end
|
324
|
-
|
325
332
|
def cp_r(dest)
|
326
333
|
FileUtils.cp_r(path, dest) #if Path[dest].exists?
|
327
334
|
end
|
@@ -333,13 +340,25 @@ class Path
|
|
333
340
|
Path[File.join(path, other)]
|
334
341
|
end
|
335
342
|
end
|
343
|
+
|
344
|
+
|
345
|
+
## Dangerous methods.
|
336
346
|
|
337
|
-
def
|
338
|
-
|
347
|
+
def rm
|
348
|
+
if directory?
|
349
|
+
Dir.rmdir(self) == 0
|
350
|
+
else
|
351
|
+
File.unlink(self) == 1
|
352
|
+
end
|
339
353
|
end
|
354
|
+
alias_method :"delete!", :rm
|
355
|
+
alias_method :"unlink!", :rm
|
356
|
+
alias_method :"remove!", :rm
|
340
357
|
|
341
|
-
|
342
|
-
|
358
|
+
def truncate(offset=0)
|
359
|
+
File.truncate(self, offset)
|
360
|
+
end
|
361
|
+
|
343
362
|
|
344
363
|
## Checksums
|
345
364
|
|
@@ -357,6 +376,25 @@ class Path
|
|
357
376
|
|
358
377
|
alias_method :md5sum, :md5
|
359
378
|
|
379
|
+
|
380
|
+
## Class method versions of FileUtils-like things
|
381
|
+
|
382
|
+
%w[
|
383
|
+
mkdir
|
384
|
+
mkdir_p
|
385
|
+
sha1
|
386
|
+
sha2
|
387
|
+
md5
|
388
|
+
rm
|
389
|
+
truncate
|
390
|
+
].each do |method|
|
391
|
+
class_eval %{
|
392
|
+
def self.#{method}(path)
|
393
|
+
Path[path].#{method}
|
394
|
+
end
|
395
|
+
}
|
396
|
+
end
|
397
|
+
|
360
398
|
end
|
361
399
|
|
362
400
|
#
|
data/spec/path_spec.rb
CHANGED
@@ -38,8 +38,7 @@ describe Path do
|
|
38
38
|
path.ext = "mkv"
|
39
39
|
path.ext.should == "mkv"
|
40
40
|
|
41
|
-
path.
|
42
|
-
path.ext.should == "mkv"
|
41
|
+
path.filename[-4..-1].should == ".mkv"
|
43
42
|
end
|
44
43
|
|
45
44
|
it "replaces filename" do
|
@@ -169,14 +168,27 @@ describe Path do
|
|
169
168
|
path.to_s.should == str+".dat"
|
170
169
|
end
|
171
170
|
|
172
|
-
it "
|
171
|
+
it "rms" do
|
173
172
|
path = Path.tmpfile
|
174
173
|
path << "data"
|
175
174
|
path.exists?.should == true
|
176
|
-
path.
|
175
|
+
path.rm.should == true
|
177
176
|
path.exists?.should == false
|
178
177
|
end
|
179
178
|
|
179
|
+
it "truncates" do
|
180
|
+
path = Path.tmpfile
|
181
|
+
|
182
|
+
path << "1"*100
|
183
|
+
path.size.should == 100
|
184
|
+
|
185
|
+
path.truncate(50)
|
186
|
+
path.size.should == 50
|
187
|
+
|
188
|
+
path.truncate
|
189
|
+
path.size.should == 0
|
190
|
+
end
|
191
|
+
|
180
192
|
it "checksums" do
|
181
193
|
a, b = Path["*.rb"].take(2)
|
182
194
|
[:sha1, :sha2, :md5].each do |meth|
|
@@ -189,4 +201,19 @@ describe Path do
|
|
189
201
|
end
|
190
202
|
end
|
191
203
|
|
204
|
+
it "mkdirs" do
|
205
|
+
tmp = Path.tmpfile
|
206
|
+
lambda { tmp.mkdir }.should raise_error
|
207
|
+
tmp.rm
|
208
|
+
tmp.mkdir.should == true
|
209
|
+
tmp.rm.should == true
|
210
|
+
end
|
211
|
+
|
212
|
+
it "has classmethods" do
|
213
|
+
path = Path.tmpfile
|
214
|
+
|
215
|
+
path << "whee"*100
|
216
|
+
path.sha1.should == Path.sha1(path)
|
217
|
+
end
|
218
|
+
|
192
219
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: epitools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.4.
|
5
|
+
version: 0.4.37
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- epitron
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-05-
|
13
|
+
date: 2011-05-29 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|