Module: PathString
- Defined in:
- lib/sugar-high/path.rb
Instance Method Summary collapse
- #dir? ⇒ Boolean (also: #is_dir?)
- #down(lv) ⇒ Object
- #exists? ⇒ Boolean (also: #there?)
- #file? ⇒ Boolean (also: #is_file?)
- #post_down(lv) ⇒ Object
- #post_up(lv) ⇒ Object
- #symlink? ⇒ Boolean (also: #is_symlink?)
- #to_dir(option = nil) ⇒ Object (also: #new_dir, #dir)
- #to_file(option = nil) ⇒ Object (also: #file, #new_file)
-
#to_symlink(new_path) ⇒ Object
(also: #new_symlink, #symlink)
, option=nil.
- #up(lv) ⇒ Object
Instance Method Details
#dir? ⇒ Boolean Also known as: is_dir?
39 40 41 |
# File 'lib/sugar-high/path.rb', line 39 def dir? File.directory? self end |
#down(lv) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/sugar-high/path.rb', line 54 def down lv up_dir = Regexp.escape('../') orig = self.clone lv.times do self.gsub! /^#{up_dir}/, '' return self if self == orig end self end |
#exists? ⇒ Boolean Also known as: there?
29 30 31 |
# File 'lib/sugar-high/path.rb', line 29 def exists? File.exist? self end |
#file? ⇒ Boolean Also known as: is_file?
34 35 36 |
# File 'lib/sugar-high/path.rb', line 34 def file? File.file? self end |
#post_down(lv) ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/sugar-high/path.rb', line 68 def post_down lv up_dir = Regexp.escape('/..') orig = self.clone lv.times do self.gsub! /#{up_dir}$/, '' return self if self == orig end self end |
#post_up(lv) ⇒ Object
64 65 66 |
# File 'lib/sugar-high/path.rb', line 64 def post_up lv self + ('/..' * lv) end |
#symlink? ⇒ Boolean Also known as: is_symlink?
45 46 47 |
# File 'lib/sugar-high/path.rb', line 45 def symlink? File.symlink? self end |
#to_dir(option = nil) ⇒ Object Also known as: new_dir, dir
15 16 17 18 |
# File 'lib/sugar-high/path.rb', line 15 def to_dir option=nil raise ArgumentError, "Dir doesn't exist" if option == :raise && !File.directory?(self) Dir.new(self) if File.directory? self end |
#to_file(option = nil) ⇒ Object Also known as: file, new_file
8 9 10 11 |
# File 'lib/sugar-high/path.rb', line 8 def to_file option=nil raise ArgumentError, "File doesn't exist" if option == :raise && !File.directory?(self) File.new(self) if File.file? self end |
#to_symlink(new_path) ⇒ Object Also known as: new_symlink, symlink
, option=nil
22 23 24 25 |
# File 'lib/sugar-high/path.rb', line 22 def to_symlink new_path #, option=nil # raise ArgumentError, "New link location doesn't exist" if option == :raise && !File.exist?(new_path) File.symlink(self, new_path) end |
#up(lv) ⇒ Object
50 51 52 |
# File 'lib/sugar-high/path.rb', line 50 def up lv ('../' * lv) + self end |