Class: WarpDrive::Path
- Inherits:
-
Object
- Object
- WarpDrive::Path
- Defined in:
- lib/warp_drive/path.rb
Overview
This class allows you to easily get the location of any file or path in a Warp Drive gem.
Example:
WarpDrive::Path.app.controllers.application_controller.rb
# => "/usr/local/lib/ruby/gems/1.8/gems/my_warp_drive_gem-1.2.3/lib/app/controllers/application_controller.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.
12 13 14 15 |
# File 'lib/warp_drive/path.rb', line 12 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
Instance Attribute Details
#parent ⇒ Object
Returns the value of attribute parent.
9 10 11 |
# File 'lib/warp_drive/path.rb', line 9 def parent @parent end |
#path ⇒ Object
Returns the value of attribute path.
10 11 12 |
# File 'lib/warp_drive/path.rb', line 10 def path @path end |
Class Method Details
Instance Method Details
#/(other) ⇒ Object
37 38 39 |
# File 'lib/warp_drive/path.rb', line 37 def /(other) File.(File.join(self.to_s, other.to_s)) end |
#to_s ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/warp_drive/path.rb', line 25 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 |