fancypath 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/fancypath.rb +29 -5
- data/spec/fancypath_spec.rb +28 -3
- data/spec/spec_helper.rb +1 -1
- metadata +3 -3
data/Rakefile
CHANGED
data/lib/fancypath.rb
CHANGED
@@ -4,18 +4,25 @@ class Pathname
|
|
4
4
|
def to_path
|
5
5
|
Fancypath.new(self)
|
6
6
|
end
|
7
|
+
|
8
|
+
alias_method :to_fancypath, :to_path
|
9
|
+
|
7
10
|
end
|
8
11
|
|
9
12
|
class String
|
10
13
|
def to_path
|
11
14
|
Fancypath.new(self)
|
12
15
|
end
|
16
|
+
|
17
|
+
alias_method :to_fancypath, :to_path
|
18
|
+
|
13
19
|
end
|
14
20
|
|
15
21
|
class Fancypath < Pathname
|
16
22
|
# methods are chainable and do what you think they do
|
17
23
|
|
18
24
|
alias_method :exists?, :exist?
|
25
|
+
alias_method :rename_to, :rename
|
19
26
|
|
20
27
|
def /(path)
|
21
28
|
self.join(path).to_path
|
@@ -24,31 +31,48 @@ class Fancypath < Pathname
|
|
24
31
|
# make file
|
25
32
|
def touch
|
26
33
|
FileUtils.touch self.to_s
|
27
|
-
self
|
34
|
+
self.to_path
|
28
35
|
end
|
29
36
|
|
30
37
|
# make dir
|
31
38
|
def create
|
32
39
|
mkpath unless exist?
|
40
|
+
self.to_path
|
41
|
+
end
|
42
|
+
|
43
|
+
def copy(dest)
|
44
|
+
FileUtils.cp(self, dest)
|
33
45
|
self
|
34
46
|
end
|
35
47
|
|
36
48
|
# file or dir
|
37
49
|
def remove
|
38
50
|
directory? ? rmtree : delete if exist?
|
39
|
-
self
|
51
|
+
self.to_path
|
40
52
|
end
|
41
53
|
|
42
|
-
def write(contents)
|
54
|
+
def write(contents, mode='wb')
|
43
55
|
dirname.create
|
44
|
-
open(
|
45
|
-
self
|
56
|
+
open(mode) { |f| f.write contents }
|
57
|
+
self.to_path
|
58
|
+
end
|
59
|
+
|
60
|
+
def append(contents)
|
61
|
+
write(contents,'a+')
|
46
62
|
end
|
47
63
|
|
48
64
|
def visible_children
|
49
65
|
children.reject { |c| c.basename.to_s =~ /^\./ }
|
50
66
|
end
|
51
67
|
|
68
|
+
def inspect
|
69
|
+
super.sub('Pathname','Fancypath')
|
70
|
+
end
|
71
|
+
|
72
|
+
def to_path
|
73
|
+
self
|
74
|
+
end
|
75
|
+
|
52
76
|
end
|
53
77
|
|
54
78
|
def Fancypath(path); Fancypath.new(path) end
|
data/spec/fancypath_spec.rb
CHANGED
@@ -12,7 +12,7 @@ after { TMP_DIR.rmtree }
|
|
12
12
|
|
13
13
|
describe '#/' do
|
14
14
|
|
15
|
-
it('returns Fancypath') { (@dir/'somefile').class.should == Fancypath }
|
15
|
+
it('returns a Fancypath') { (@dir/'somefile').class.should == Fancypath }
|
16
16
|
it('joins paths') { (@dir/'somefile').to_s.should =~ /\/somefile$/ }
|
17
17
|
|
18
18
|
end
|
@@ -20,13 +20,15 @@ end
|
|
20
20
|
describe '#touch', 'file does not exist' do
|
21
21
|
|
22
22
|
it('returns self') { @file.touch.should == @file }
|
23
|
+
it('returns a Fancypath') { @file.touch.should be_instance_of(Fancypath) }
|
23
24
|
it('creates file') { @file.touch.should be_file }
|
24
25
|
|
25
26
|
end
|
26
27
|
|
27
28
|
describe '#create', 'dir does not exist' do
|
28
29
|
|
29
|
-
it('returns self') { @dir.create.should == @dir }
|
30
|
+
it('returns self') { @dir.create.should == @dir }
|
31
|
+
it('returns a Fancypath') { @dir.create.should be_instance_of(Fancypath) }
|
30
32
|
it('creates directory') { @dir.create.should be_directory }
|
31
33
|
|
32
34
|
end
|
@@ -34,6 +36,7 @@ end
|
|
34
36
|
describe '#remove' do
|
35
37
|
|
36
38
|
it('returns self') { @file.remove.should == @file }
|
39
|
+
it('returns a Fancypath') { @file.remove.should be_instance_of(Fancypath) }
|
37
40
|
it('removes file') { @file.touch.remove.should_not exist }
|
38
41
|
it('removes directory') { @dir.create.remove.should_not exist }
|
39
42
|
|
@@ -42,9 +45,31 @@ end
|
|
42
45
|
describe '#write' do
|
43
46
|
|
44
47
|
it('returns self') { @file.write('').should == @file }
|
48
|
+
it('returns a Fancypath') { @file.write('').should be_instance_of(Fancypath) }
|
45
49
|
it('writes contents to file') { @file.write('test').read.should == 'test' }
|
46
50
|
|
47
51
|
end
|
48
52
|
|
53
|
+
describe '#copy' do
|
54
|
+
|
55
|
+
before { @file.touch }
|
56
|
+
it('returns a Fancypath') { @file.copy(TMP_DIR/'foo').should be_instance_of(Fancypath) }
|
57
|
+
it('creates a new file') { @file.copy(TMP_DIR/'foo').should exist }
|
58
|
+
it('keeps the original') { @file.copy(TMP_DIR/'foo'); @file.should exist }
|
59
|
+
it('copies the contents') { @file.copy(TMP_DIR/'foo').read.should == @file.read }
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end #/Fancypath
|
64
|
+
|
65
|
+
describe "String#to_path" do
|
66
|
+
|
67
|
+
it('returns a Fancypath') { 'test'.to_path.should be_instance_of(Fancypath) }
|
68
|
+
|
69
|
+
end
|
49
70
|
|
50
|
-
|
71
|
+
describe "Pathname#to_path" do
|
72
|
+
|
73
|
+
it('returns a Fancypath') { Fancypath.new('/').to_path.should be_instance_of(Fancypath) }
|
74
|
+
|
75
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fancypath
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Myles Byrne
|
@@ -10,7 +10,7 @@ autorequire: fancypath
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2008-11-
|
13
|
+
date: 2008-11-24 00:00:00 +11:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|
@@ -52,7 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
52
|
requirements: []
|
53
53
|
|
54
54
|
rubyforge_project:
|
55
|
-
rubygems_version: 1.
|
55
|
+
rubygems_version: 1.3.1
|
56
56
|
signing_key:
|
57
57
|
specification_version: 2
|
58
58
|
summary: Extensions for the Pathname library.
|