pathstring 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pathstring.rb +2 -2
- data/lib/pathstring/version.rb +1 -1
- data/lib/pathstring_root.rb +10 -5
- metadata +2 -2
data/lib/pathstring.rb
CHANGED
@@ -58,11 +58,11 @@ class Pathstring < String
|
|
58
58
|
|
59
59
|
# (re)set the relative origin
|
60
60
|
# set the relative facade in the process
|
61
|
-
def with_relative_root(root)
|
61
|
+
def with_relative_root(*root)
|
62
62
|
# Tap because i like tap
|
63
63
|
# No, tap because i want this to be chainable with `new` for example
|
64
64
|
tap do |p|
|
65
|
-
relative_root_with root
|
65
|
+
relative_root_with File.join(root)
|
66
66
|
relative_with @absolute.relative_path_from(@relative_root)
|
67
67
|
end
|
68
68
|
end
|
data/lib/pathstring/version.rb
CHANGED
data/lib/pathstring_root.rb
CHANGED
@@ -7,18 +7,18 @@ class PathstringRoot < Pathstring
|
|
7
7
|
# last selected element
|
8
8
|
attr_reader :last
|
9
9
|
|
10
|
-
attr_writer :
|
10
|
+
attr_writer :branching_class
|
11
11
|
|
12
12
|
# Useful memoize.
|
13
13
|
# Needed to be done here because i
|
14
14
|
# really don't want to do it enroot
|
15
15
|
def select(path)
|
16
|
-
@last = enroot path
|
16
|
+
@last = enroot path if path
|
17
17
|
end
|
18
18
|
|
19
19
|
# instantiate with parameter and set the right facade
|
20
20
|
def enroot(path)
|
21
|
-
|
21
|
+
branching_class.new(path, self).tap { |e| e.relative! }
|
22
22
|
end
|
23
23
|
|
24
24
|
# list of an element's children as instances of the
|
@@ -31,13 +31,18 @@ class PathstringRoot < Pathstring
|
|
31
31
|
nil
|
32
32
|
end
|
33
33
|
|
34
|
+
# a little utility method to make PathstringRoot complete
|
35
|
+
def read(path=nil)
|
36
|
+
(select(path) || @last).read rescue nil
|
37
|
+
end
|
38
|
+
|
34
39
|
private
|
35
40
|
|
36
|
-
def
|
41
|
+
def branching_class
|
37
42
|
# inject is a funny way to do recursive stuff
|
38
43
|
# (here to find a constant starting from Object)
|
39
44
|
# Plip::Plap::PlopRoot will instantiate Plip::Plap::Plop objects
|
40
|
-
@
|
45
|
+
@branching_class ||= self.class.name.sub(/Root$/, '').split('::').inject(Object) do |constant, chunk|
|
41
46
|
constant = constant.const_get chunk
|
42
47
|
end
|
43
48
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pathstring
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: pedlar
|