chrislloyd-fancypath 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'date'
5
5
  require 'spec/rake/spectask'
6
6
 
7
7
  GEM = "fancypath"
8
- GEM_VERSION = "0.1.0"
8
+ GEM_VERSION = "0.2.0"
9
9
  AUTHORS = ["Myles Byrne", "Chris Lloyd"]
10
10
  EMAIL = "myles@ducknewmedia.com"
11
11
  HOMEPAGE = "http://ducknewmedia.com/fancypath"
data/lib/fancypath.rb CHANGED
@@ -31,31 +31,43 @@ class Fancypath < Pathname
31
31
  # make file
32
32
  def touch
33
33
  FileUtils.touch self.to_s
34
- self
34
+ self.to_path
35
35
  end
36
36
 
37
37
  # make dir
38
38
  def create
39
39
  mkpath unless exist?
40
- self
40
+ self.to_path
41
41
  end
42
42
 
43
43
  # file or dir
44
44
  def remove
45
45
  directory? ? rmtree : delete if exist?
46
- self
46
+ self.to_path
47
47
  end
48
48
 
49
- def write(contents)
49
+ def write(contents, mode='wb')
50
50
  dirname.create
51
- open('wb') { |f| f.write contents }
52
- self
51
+ open(mode) { |f| f.write contents }
52
+ self.to_path
53
+ end
54
+
55
+ def append(contents)
56
+ write(contents,'a+')
53
57
  end
54
58
 
55
59
  def visible_children
56
60
  children.reject { |c| c.basename.to_s =~ /^\./ }
57
61
  end
58
62
 
63
+ def inspect
64
+ super.sub('Pathname','Fancypath')
65
+ end
66
+
67
+ def to_path
68
+ self
69
+ end
70
+
59
71
  end
60
72
 
61
73
  def Fancypath(path); Fancypath.new(path) 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,21 @@ 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
+ end #/Fancypath
49
54
 
50
- end #/Fancypath
55
+ describe "String#to_path" do
56
+
57
+ it('returns a Fancypath') { 'test'.to_path.should be_instance_of(Fancypath) }
58
+
59
+ end
60
+
61
+ describe "Pathname#to_path" do
62
+
63
+ it('returns a Fancypath') { Fancypath.new('/').to_path.should be_instance_of(Fancypath) }
64
+
65
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chrislloyd-fancypath
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.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-02 00:00:00 -07:00
13
+ date: 2008-11-15 00:00:00 -08:00
14
14
  default_executable:
15
15
  dependencies: []
16
16