path2 0.2.0 → 0.2.1
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/lib/path2/version.rb +3 -0
- data/lib/path2.rb +25 -4
- metadata +4 -3
data/lib/path2.rb
CHANGED
@@ -5,7 +5,21 @@ class Path
|
|
5
5
|
def initialize(*args)
|
6
6
|
@options = args.last.is_a?(Hash) ? args.pop : {}
|
7
7
|
@options[:recursive] ||= false
|
8
|
-
@
|
8
|
+
@options[:short] ||= false
|
9
|
+
@root = args.first
|
10
|
+
@entries = build_entries(@root)
|
11
|
+
end
|
12
|
+
|
13
|
+
def current
|
14
|
+
File.expand_path(@root)
|
15
|
+
end
|
16
|
+
|
17
|
+
def exists?(path = nil)
|
18
|
+
if path
|
19
|
+
File.exists?([current, path].join("/"))
|
20
|
+
else
|
21
|
+
File.exists?(current)
|
22
|
+
end
|
9
23
|
end
|
10
24
|
|
11
25
|
def find(arg)
|
@@ -13,7 +27,13 @@ class Path
|
|
13
27
|
end
|
14
28
|
|
15
29
|
def join(path)
|
16
|
-
Path.new(
|
30
|
+
Path.new([@root, path].join("/"), @options)
|
31
|
+
end
|
32
|
+
|
33
|
+
def walk(path)
|
34
|
+
yield Path.new([@root, path].join("/"), @options)
|
35
|
+
ensure
|
36
|
+
self
|
17
37
|
end
|
18
38
|
|
19
39
|
def grep(pattern)
|
@@ -44,8 +64,9 @@ class Path
|
|
44
64
|
end
|
45
65
|
end
|
46
66
|
|
47
|
-
def build_entries(
|
48
|
-
|
67
|
+
def build_entries(path)
|
68
|
+
path = File.expand_path(path) if @options[:short]
|
69
|
+
dir(path).uniq
|
49
70
|
end
|
50
71
|
|
51
72
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: path2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -19,6 +19,7 @@ extra_rdoc_files: []
|
|
19
19
|
files:
|
20
20
|
- README.md
|
21
21
|
- LICENSE
|
22
|
+
- lib/path2/version.rb
|
22
23
|
- lib/path2.rb
|
23
24
|
homepage: http://github.com/bry4n/path2
|
24
25
|
licenses: []
|
@@ -34,7 +35,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
34
35
|
version: '0'
|
35
36
|
segments:
|
36
37
|
- 0
|
37
|
-
hash:
|
38
|
+
hash: 4230538922531212955
|
38
39
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
40
|
none: false
|
40
41
|
requirements:
|
@@ -43,7 +44,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
43
44
|
version: '0'
|
44
45
|
segments:
|
45
46
|
- 0
|
46
|
-
hash:
|
47
|
+
hash: 4230538922531212955
|
47
48
|
requirements: []
|
48
49
|
rubyforge_project:
|
49
50
|
rubygems_version: 1.8.11
|