chrislloyd-fancypath 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +57 -0
- data/lib/fancypath.rb +61 -0
- data/spec/fancypath_spec.rb +50 -0
- data/spec/spec_helper.rb +6 -0
- metadata +60 -0
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
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,61 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
class Pathname
|
4
|
+
def to_path
|
5
|
+
Fancypath.new(self)
|
6
|
+
end
|
7
|
+
|
8
|
+
alias_method :to_fancypath, :to_path
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
class String
|
13
|
+
def to_path
|
14
|
+
Fancypath.new(self)
|
15
|
+
end
|
16
|
+
|
17
|
+
alias_method :to_fancypath, :to_path
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
class Fancypath < Pathname
|
22
|
+
# methods are chainable and do what you think they do
|
23
|
+
|
24
|
+
alias_method :exists?, :exist?
|
25
|
+
alias_method :rename_to, :rename
|
26
|
+
|
27
|
+
def /(path)
|
28
|
+
self.join(path).to_path
|
29
|
+
end
|
30
|
+
|
31
|
+
# make file
|
32
|
+
def touch
|
33
|
+
FileUtils.touch self.to_s
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
# make dir
|
38
|
+
def create
|
39
|
+
mkpath unless exist?
|
40
|
+
self
|
41
|
+
end
|
42
|
+
|
43
|
+
# file or dir
|
44
|
+
def remove
|
45
|
+
directory? ? rmtree : delete if exist?
|
46
|
+
self
|
47
|
+
end
|
48
|
+
|
49
|
+
def write(contents)
|
50
|
+
dirname.create
|
51
|
+
open('wb') { |f| f.write contents }
|
52
|
+
self
|
53
|
+
end
|
54
|
+
|
55
|
+
def visible_children
|
56
|
+
children.reject { |c| c.basename.to_s =~ /^\./ }
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
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
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chrislloyd-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-02 00:00:00 -07: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
|
+
|