fancypath 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Myles Byrne, Chris Lloyd
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ == fancypath
2
+
3
+ Extensions to the Pathname library to model file IO in an OO mannor.
data/Rakefile ADDED
@@ -0,0 +1,57 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require 'rubygems/specification'
4
+ require 'date'
5
+ require 'spec/rake/spectask'
6
+
7
+ GEM = "fancypath"
8
+ GEM_VERSION = "0.1.0"
9
+ AUTHORS = ["Myles Byrne", "Chris Lloyd"]
10
+ EMAIL = "myles@ducknewmedia.com"
11
+ HOMEPAGE = "http://ducknewmedia.com/fancypath"
12
+ SUMMARY = "Extensions for the Pathname library."
13
+
14
+ spec = Gem::Specification.new do |s|
15
+ s.name = GEM
16
+ s.version = GEM_VERSION
17
+ s.platform = Gem::Platform::RUBY
18
+ s.has_rdoc = true
19
+ s.extra_rdoc_files = ['README.rdoc', 'LICENSE']
20
+ s.summary = SUMMARY
21
+ s.description = s.summary
22
+ s.authors = AUTHORS
23
+ s.email = EMAIL
24
+ s.homepage = HOMEPAGE
25
+
26
+ # Uncomment this to add a dependency
27
+ # s.add_dependency "foo"
28
+
29
+ s.require_path = 'lib'
30
+ s.autorequire = GEM
31
+ s.files = %w(LICENSE README.rdoc Rakefile) + Dir.glob("{lib,spec}/**/*")
32
+ end
33
+
34
+ task :default => :spec
35
+
36
+ desc "Run specs"
37
+ Spec::Rake::SpecTask.new do |t|
38
+ t.spec_files = FileList['spec/**/*_spec.rb']
39
+ t.spec_opts = %w(-fs --color)
40
+ end
41
+
42
+
43
+ Rake::GemPackageTask.new(spec) do |pkg|
44
+ pkg.gem_spec = spec
45
+ end
46
+
47
+ desc "install the gem locally"
48
+ task :install => [:package] do
49
+ sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
50
+ end
51
+
52
+ desc "create a gemspec file"
53
+ task :make_spec do
54
+ File.open("#{GEM}.gemspec", "w") do |file|
55
+ file.puts spec.to_ruby
56
+ end
57
+ end
data/lib/fancypath.rb ADDED
@@ -0,0 +1,54 @@
1
+ require 'pathname'
2
+
3
+ class Pathname
4
+ def to_path
5
+ Fancypath.new(self)
6
+ end
7
+ end
8
+
9
+ class String
10
+ def to_path
11
+ Fancypath.new(self)
12
+ end
13
+ end
14
+
15
+ class Fancypath < Pathname
16
+ # methods are chainable and do what you think they do
17
+
18
+ alias_method :exists?, :exist?
19
+
20
+ def /(path)
21
+ self.join(path).to_path
22
+ end
23
+
24
+ # make file
25
+ def touch
26
+ FileUtils.touch self.to_s
27
+ self
28
+ end
29
+
30
+ # make dir
31
+ def create
32
+ mkpath unless exist?
33
+ self
34
+ end
35
+
36
+ # file or dir
37
+ def remove
38
+ directory? ? rmtree : delete if exist?
39
+ self
40
+ end
41
+
42
+ def write(contents)
43
+ dirname.create
44
+ open('wb') { |f| f.write contents }
45
+ self
46
+ end
47
+
48
+ def visible_children
49
+ children.reject { |c| c.basename.to_s =~ /^\./ }
50
+ end
51
+
52
+ end
53
+
54
+ def Fancypath(path); Fancypath.new(path) end
@@ -0,0 +1,50 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe Fancypath do
4
+
5
+ before do
6
+ TMP_DIR.rmtree if TMP_DIR.exist?
7
+ TMP_DIR.mkpath
8
+ @file = TMP_DIR.to_path/'testfile'
9
+ @dir = TMP_DIR.to_path/'testdir'
10
+ end
11
+ after { TMP_DIR.rmtree }
12
+
13
+ describe '#/' do
14
+
15
+ it('returns Fancypath') { (@dir/'somefile').class.should == Fancypath }
16
+ it('joins paths') { (@dir/'somefile').to_s.should =~ /\/somefile$/ }
17
+
18
+ end
19
+
20
+ describe '#touch', 'file does not exist' do
21
+
22
+ it('returns self') { @file.touch.should == @file }
23
+ it('creates file') { @file.touch.should be_file }
24
+
25
+ end
26
+
27
+ describe '#create', 'dir does not exist' do
28
+
29
+ it('returns self') { @dir.create.should == @dir }
30
+ it('creates directory') { @dir.create.should be_directory }
31
+
32
+ end
33
+
34
+ describe '#remove' do
35
+
36
+ it('returns self') { @file.remove.should == @file }
37
+ it('removes file') { @file.touch.remove.should_not exist }
38
+ it('removes directory') { @dir.create.remove.should_not exist }
39
+
40
+ end
41
+
42
+ describe '#write' do
43
+
44
+ it('returns self') { @file.write('').should == @file }
45
+ it('writes contents to file') { @file.write('test').read.should == 'test' }
46
+
47
+ end
48
+
49
+
50
+ end #/Fancypath
@@ -0,0 +1,6 @@
1
+ $TESTING=true
2
+ $:.push File.join(File.dirname(__FILE__), '..', 'lib')
3
+
4
+ require 'fancypath'
5
+
6
+ TMP_DIR = Pathname.new(__FILE__).dirname.join('..', 'tmp', 'fancypath')
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fancypath
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Myles Byrne
8
+ - Chris Lloyd
9
+ autorequire: fancypath
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2008-11-03 00:00:00 +11:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: Extensions for the Pathname library.
18
+ email: myles@ducknewmedia.com
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files:
24
+ - README.rdoc
25
+ - LICENSE
26
+ files:
27
+ - LICENSE
28
+ - README.rdoc
29
+ - Rakefile
30
+ - lib/fancypath.rb
31
+ - spec/fancypath_spec.rb
32
+ - spec/spec_helper.rb
33
+ has_rdoc: true
34
+ homepage: http://ducknewmedia.com/fancypath
35
+ post_install_message:
36
+ rdoc_options: []
37
+
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "0"
45
+ version:
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ requirements: []
53
+
54
+ rubyforge_project:
55
+ rubygems_version: 1.2.0
56
+ signing_key:
57
+ specification_version: 2
58
+ summary: Extensions for the Pathname library.
59
+ test_files: []
60
+