fspath 0.0.2.5-darwin → 0.0.3-darwin
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 +1 -1
- data/fspath.gemspec +2 -2
- data/lib/fspath.rb +37 -9
- data/spec/fspath_spec.rb +63 -0
- metadata +4 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/fspath.gemspec
CHANGED
@@ -5,12 +5,12 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{fspath}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.3"
|
9
9
|
s.platform = %q{darwin}
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.authors = ["Boba Fat"]
|
13
|
-
s.date = %q{2010-12-
|
13
|
+
s.date = %q{2010-12-12}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE.txt",
|
16
16
|
"README.rdoc"
|
data/lib/fspath.rb
CHANGED
@@ -1,27 +1,55 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
1
3
|
class FSPath < Pathname
|
2
4
|
class << self
|
3
|
-
#
|
4
|
-
#
|
5
|
+
# Return current user home path if called without argument.
|
6
|
+
# If called with argument return specified user home path.
|
5
7
|
def ~(name = nil)
|
6
8
|
new(File.expand_path("~#{name}"))
|
7
9
|
end
|
8
10
|
end
|
9
11
|
|
10
|
-
#
|
12
|
+
# Join paths using File.join
|
11
13
|
def /(other)
|
12
14
|
self.class.new(File.join(@path, other.to_s))
|
13
15
|
end
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
17
|
+
unless (new('a') + 'b').is_a?(self)
|
18
|
+
# Fixing Pathname.+
|
19
|
+
def +(part)
|
20
|
+
self.class.new(super + part)
|
21
|
+
end
|
18
22
|
end
|
19
23
|
|
20
|
-
|
21
|
-
|
22
|
-
|
24
|
+
# Write data to file
|
25
|
+
def write(data)
|
26
|
+
open('wb') do |f|
|
27
|
+
f.write(data)
|
23
28
|
end
|
24
29
|
end
|
30
|
+
|
31
|
+
# Append data to file
|
32
|
+
def append(data)
|
33
|
+
open('ab') do |f|
|
34
|
+
f.write(data)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Escape characters in glob pattern
|
39
|
+
def escape_glob
|
40
|
+
self.class.new(@path.gsub(/([\*\?\[\]\{\}])/, '\\\\\1'))
|
41
|
+
end
|
42
|
+
|
43
|
+
# Expand glob
|
44
|
+
def glob(*args, &block)
|
45
|
+
flags = args.last.is_a?(Fixnum) ? args.pop : nil
|
46
|
+
args = [File.join(self, *args)]
|
47
|
+
args << flags if flags
|
48
|
+
self.class.glob(*args, &block)
|
49
|
+
end
|
50
|
+
|
51
|
+
if RUBY_PLATFORM.downcase.include?('darwin')
|
52
|
+
end
|
25
53
|
end
|
26
54
|
|
27
55
|
module Kernel
|
data/spec/fspath_spec.rb
CHANGED
@@ -38,4 +38,67 @@ describe FSPath do
|
|
38
38
|
(FSPath('a') + 'b').should be_instance_of(FSPath)
|
39
39
|
end
|
40
40
|
end
|
41
|
+
|
42
|
+
describe "writing" do
|
43
|
+
before do
|
44
|
+
@path = FSPath.new('test')
|
45
|
+
@file = mock(:file)
|
46
|
+
@data = mock(:data)
|
47
|
+
@size = mock(:size)
|
48
|
+
|
49
|
+
@path.stub!(:open).and_yield(@file)
|
50
|
+
@file.stub!(:write).and_return(@size)
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "write" do
|
54
|
+
it "should open file for writing" do
|
55
|
+
@path.should_receive(:open).with('wb')
|
56
|
+
@path.write(@data)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should write data" do
|
60
|
+
@file.should_receive(:write).with(@data)
|
61
|
+
@path.write(@data)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should return result of write" do
|
65
|
+
@path.write(@data).should == @size
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "append" do
|
70
|
+
it "should open file for writing" do
|
71
|
+
@path.should_receive(:open).with('ab')
|
72
|
+
@path.append(@data)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should write data" do
|
76
|
+
@file.should_receive(:write).with(@data)
|
77
|
+
@path.append(@data)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should return result of write" do
|
81
|
+
@path.append(@data).should == @size
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "escape_glob" do
|
87
|
+
it "should escape glob pattern characters" do
|
88
|
+
FSPath('*/**/?[a-z]{abc,def}').escape_glob.should == FSPath('\*/\*\*/\?\[a-z\]\{abc,def\}')
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "glob" do
|
93
|
+
it "should join with arguments and expand glob" do
|
94
|
+
FSPath.should_receive(:glob).with('a/b/c/**/*')
|
95
|
+
FSPath('a/b/c').glob('**', '*')
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should join with arguments and expand glob" do
|
99
|
+
@flags = 12345
|
100
|
+
FSPath.should_receive(:glob).with('a/b/c/**/*', @flags)
|
101
|
+
FSPath('a/b/c').glob('**', '*', @flags)
|
102
|
+
end
|
103
|
+
end
|
41
104
|
end
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fspath
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
|
11
|
-
version: 0.0.2.5
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
12
11
|
platform: darwin
|
13
12
|
authors:
|
14
13
|
- Boba Fat
|
@@ -16,7 +15,7 @@ autorequire:
|
|
16
15
|
bindir: bin
|
17
16
|
cert_chain: []
|
18
17
|
|
19
|
-
date: 2010-12-
|
18
|
+
date: 2010-12-12 00:00:00 +03:00
|
20
19
|
default_executable:
|
21
20
|
dependencies:
|
22
21
|
- !ruby/object:Gem::Dependency
|