Class: Polyamory::RootedPathname
- Inherits:
-
Pathname
- Object
- Pathname
- Polyamory::RootedPathname
- Defined in:
- lib/polyamory/rooted_pathname.rb
Overview
A kind of Pathname that keeps a reference to a root directory and is able to return a relativized pathname from that particular root.
Instance Attribute Summary collapse
-
#root ⇒ Object
Returns the value of attribute root.
Class Method Summary collapse
-
.glob(patterns, root) ⇒ Object
Find pathnames matching the glob pattern and assign to them a root.
Instance Method Summary collapse
-
#+(other) ⇒ Object
Add to the current path; the result has the current path as root.
-
#=~(pattern) ⇒ Object
Perform a regex match only on the relative portion of the path.
-
#in_dir?(dir) ⇒ Boolean
Check if current path is contained in directory.
-
#initialize(path, root_path = nil) ⇒ RootedPathname
constructor
A new instance of RootedPathname.
-
#relative ⇒ Object
Return the relative portion of the path from root.
Constructor Details
#initialize(path, root_path = nil) ⇒ RootedPathname
Returns a new instance of RootedPathname.
17 18 19 20 |
# File 'lib/polyamory/rooted_pathname.rb', line 17 def initialize(path, root_path = nil) super(path) self.root = root_path end |
Instance Attribute Details
#root ⇒ Object
Returns the value of attribute root.
7 8 9 |
# File 'lib/polyamory/rooted_pathname.rb', line 7 def root @root end |
Class Method Details
Instance Method Details
#+(other) ⇒ Object
Add to the current path; the result has the current path as root
45 46 47 48 49 |
# File 'lib/polyamory/rooted_pathname.rb', line 45 def +(other) result = self.class.new(plus(@path, other.to_s)) result.root ||= self result end |
#=~(pattern) ⇒ Object
Perform a regex match only on the relative portion of the path
40 41 42 |
# File 'lib/polyamory/rooted_pathname.rb', line 40 def =~(pattern) relative.to_s =~ pattern end |
#in_dir?(dir) ⇒ Boolean
Check if current path is contained in directory
34 35 36 37 |
# File 'lib/polyamory/rooted_pathname.rb', line 34 def in_dir? dir self == dir or self.to_s.index(File.join(dir, '')) == 0 end |
#relative ⇒ Object
Return the relative portion of the path from root
28 29 30 31 |
# File 'lib/polyamory/rooted_pathname.rb', line 28 def relative return self if relative? @relativized ||= relative_path_from root end |