Class: WarpDrive::Path
- Inherits:
-
Object
- Object
- WarpDrive::Path
- Defined in:
- lib/warp_drive/path.rb
Instance Attribute Summary collapse
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#path ⇒ Object
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #/(other) ⇒ Object
-
#initialize(parent, path) ⇒ Path
constructor
A new instance of Path.
- #method_missing(sym, *args) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(parent, path) ⇒ Path
Returns a new instance of Path.
7 8 9 10 |
# File 'lib/warp_drive/path.rb', line 7 def initialize(parent, path) self.parent = parent self.path = path.to_s end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/warp_drive/path.rb', line 12 def method_missing(sym, *args) if sym == :rb || sym == :yml return self.to_s + ".#{sym}" else WarpDrive::Path.new(self, sym) end end |
Instance Attribute Details
#parent ⇒ Object
Returns the value of attribute parent.
4 5 6 |
# File 'lib/warp_drive/path.rb', line 4 def parent @parent end |
#path ⇒ Object
Returns the value of attribute path.
5 6 7 |
# File 'lib/warp_drive/path.rb', line 5 def path @path end |
Class Method Details
.method_missing(sym, *args) ⇒ Object
38 39 40 |
# File 'lib/warp_drive/path.rb', line 38 def method_missing(sym, *args) WarpDrive::Path.new(nil, sym) end |
Instance Method Details
#/(other) ⇒ Object
32 33 34 |
# File 'lib/warp_drive/path.rb', line 32 def /(other) File.(File.join(self.to_s, other.to_s)) end |
#to_s ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/warp_drive/path.rb', line 20 def to_s paths = [self.path] par = self.parent until par.nil? paths << par.path par = par.parent end paths << File.join(WarpDrive::ROOT) path = File.(File.join(paths.reverse)) return path end |