Class: MockFS::Path
- Inherits:
-
String
- Object
- String
- MockFS::Path
- Defined in:
- lib/mockfs.rb
Overview
:nodoc:
Constant Summary collapse
- @@getwd =
nil
Class Method Summary collapse
Instance Method Summary collapse
- #[](*args) ⇒ Object
- #absolute ⇒ Object
- #first ⇒ Object
- #last ⇒ Object
- #node ⇒ Object
- #parent ⇒ Object
- #size ⇒ Object
- #strip ⇒ Object
Class Method Details
.getwd ⇒ Object
524 525 526 527 |
# File 'lib/mockfs.rb', line 524 def self.getwd @@getwd = Dir.getwd if @@getwd.nil? @@getwd end |
Instance Method Details
#[](*args) ⇒ Object
529 530 531 532 533 534 535 |
# File 'lib/mockfs.rb', line 529 def []( *args ) if args.size == 1 and args.first.is_a? Fixnum Path.new self.split( "/" )[*args] else Path.new self.split( "/" )[*args].join( "/" ) end end |
#absolute ⇒ Object
537 538 539 540 541 542 543 544 545 546 |
# File 'lib/mockfs.rb', line 537 def absolute if self =~ %r{^\w} Path.new( File.join( self.class.getwd, self ) ) else new_str = self.to_s new_str.gsub!( %r{^\.\.}, self.class.getwd + '/..' ) new_str.gsub!( %r{^\.}, self.class.getwd ) Path.new( new_str ) end end |
#first ⇒ Object
548 |
# File 'lib/mockfs.rb', line 548 def first; self.split( "/" ).first; end |
#last ⇒ Object
550 |
# File 'lib/mockfs.rb', line 550 def last; self.split( "/" ).last; end |
#node ⇒ Object
552 553 554 555 |
# File 'lib/mockfs.rb', line 552 def node self =~ %r{^(.*)/(.*?)$} $2 end |
#parent ⇒ Object
557 558 559 560 |
# File 'lib/mockfs.rb', line 557 def parent self =~ %r{^(.*)/(.*?)$} $1 end |
#size ⇒ Object
562 |
# File 'lib/mockfs.rb', line 562 def size; self.split( '/' ).size; end |
#strip ⇒ Object
564 |
# File 'lib/mockfs.rb', line 564 def strip; self.gsub( %r{^/+}, '' ).gsub( %r{/+$}, '' ); end |