epitools 0.4.41 → 0.4.42

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 CHANGED
@@ -1 +1 @@
1
- 0.4.41
1
+ 0.4.42
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{epitools}
8
- s.version = "0.4.41"
8
+ s.version = "0.4.42"
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,70 +12,21 @@ class Path
12
12
  Dir[str].map { |entry| new(entry) }
13
13
  end
14
14
 
15
- def self.[](str)
16
- if str =~ %r{^[a-z\-]+://}i # URL?
17
- Path::URL.new(str)
18
- elsif str =~ /[\?\*]/ and not str =~ /\\[\?\*]/ # contains glob chars? (unescaped)
19
- glob(str)
20
- else
21
- new(str)
15
+ def self.[](path)
16
+ case path
17
+ when Path
18
+ path
19
+ when String
20
+ if path =~ %r{^[a-z\-]+://}i # URL?
21
+ Path::URL.new(path)
22
+ elsif path =~ /[\?\*]/ and not path =~ /\\[\?\*]/ # contains glob chars? (unescaped)
23
+ glob(path)
24
+ else
25
+ new(path)
26
+ end
22
27
  end
23
28
  end
24
29
 
25
- #
26
- # TODO: Remove the tempfile when the Path object is garbage collected or freed.
27
- #
28
- def self.tmpfile(prefix="tmp")
29
- path = Path[ Tempfile.new(prefix).path ]
30
- yield path if block_given?
31
- path
32
- end
33
- alias_class_method :tempfile, :tmpfile
34
-
35
- def self.home
36
- Path[ENV['HOME']]
37
- end
38
-
39
- def self.pwd
40
- File.expand_path Dir.pwd
41
- end
42
-
43
- def self.pushd
44
- @@dir_stack ||= []
45
- @@dir_stack.push pwd
46
- end
47
-
48
- def self.popd
49
- @@dir_stack ||= [pwd]
50
- @@dir_stack.pop
51
- end
52
-
53
- def self.cd(dest); Dir.chdir(dest); end
54
-
55
- def self.ls(path); Path[path].ls end
56
-
57
- def self.ls_r(path); Path[path].ls_r; end
58
-
59
- ## TODO: Verbose mode
60
- #def self.verbose=(value); @@verbose = value; end
61
- #def self.verbose; @@verbose ||= false; end
62
-
63
- if Sys.windows?
64
- PATH_SEPARATOR = ";"
65
- BINARY_EXTENSION = ".exe"
66
- else
67
- PATH_SEPARATOR = ":"
68
- BINARY_EXTENSION = ""
69
- end
70
-
71
- def self.which(bin)
72
- ENV["PATH"].split(PATH_SEPARATOR).find do |path|
73
- result = (Path[path] / (bin + BINARY_EXTENSION))
74
- return result if result.exists?
75
- end
76
- nil
77
- end
78
-
79
30
  ## setters
80
31
 
81
32
  attr_writer :base
@@ -257,7 +208,6 @@ class Path
257
208
  Path.new( File.join(self, other) )
258
209
  end
259
210
 
260
-
261
211
  ## opening/reading files
262
212
 
263
213
  def open(mode="rb", &block)
@@ -365,11 +315,15 @@ class Path
365
315
  end
366
316
  end
367
317
 
318
+ def ln_s(dest)
319
+ dest = Path[dest]
320
+ FileUtils.ln_s self, dest
321
+ end
368
322
 
369
323
  ## Dangerous methods.
370
324
 
371
325
  def rm
372
- if directory?
326
+ if directory? and not symlink?
373
327
  Dir.rmdir(self) == 0
374
328
  else
375
329
  File.unlink(self) == 1
@@ -501,12 +455,71 @@ class Path
501
455
  # TODO: return the extension for the mime type.
502
456
  raise NotImplementedError
503
457
  end
458
+
459
+ ############################################################################
460
+ ## Class Methods
461
+
462
+ #
463
+ # TODO: Remove the tempfile when the Path object is garbage collected or freed.
464
+ #
465
+ def self.tmpfile(prefix="tmp")
466
+ path = Path[ Tempfile.new(prefix).path ]
467
+ yield path if block_given?
468
+ path
469
+ end
470
+ alias_class_method :tempfile, :tmpfile
471
+
472
+ def self.home
473
+ Path[ENV['HOME']]
474
+ end
475
+
476
+ def self.pwd
477
+ File.expand_path Dir.pwd
478
+ end
479
+
480
+ def self.pushd
481
+ @@dir_stack ||= []
482
+ @@dir_stack.push pwd
483
+ end
484
+
485
+ def self.popd
486
+ @@dir_stack ||= [pwd]
487
+ @@dir_stack.pop
488
+ end
489
+
490
+ def self.cd(dest); Dir.chdir(dest); end
491
+
492
+ def self.ls(path); Path[path].ls end
493
+
494
+ def self.ls_r(path); Path[path].ls_r; end
495
+
496
+ def self.ln_s(src, dest); Path[src].ln_s(dest); end
497
+
498
+ ## TODO: Verbose mode
499
+ #def self.verbose=(value); @@verbose = value; end
500
+ #def self.verbose; @@verbose ||= false; end
501
+
502
+ if Sys.windows?
503
+ PATH_SEPARATOR = ";"
504
+ BINARY_EXTENSION = ".exe"
505
+ else
506
+ PATH_SEPARATOR = ":"
507
+ BINARY_EXTENSION = ""
508
+ end
509
+
510
+ def self.which(bin)
511
+ ENV["PATH"].split(PATH_SEPARATOR).find do |path|
512
+ result = (Path[path] / (bin + BINARY_EXTENSION))
513
+ return result if result.exists?
514
+ end
515
+ nil
516
+ end
504
517
 
505
518
  end
506
519
 
507
520
 
508
521
  #
509
- # A wrapper for URL objects
522
+ # A wrapper for URL objects.
510
523
  #
511
524
  class Path::URL < Path
512
525
 
@@ -254,4 +254,9 @@ describe Path do
254
254
  Path.which("asdfasdfhkajlsdhfkljashdf").should be_nil
255
255
  end
256
256
 
257
+ it "Path[]s another path" do
258
+ path = Path.tmpfile
259
+ Path[path].path.should == path.path
260
+ end
261
+
257
262
  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.41
5
+ version: 0.4.42
6
6
  platform: ruby
7
7
  authors:
8
8
  - epitron