class Begin::Path
The canonical file path representation used throughout the application. Paths are immediately expanded into absolute file paths on construction
Public Class Methods
new(path, parent_dir, help)
click to toggle source
# File lib/begin/path.rb, line 5 def initialize(path, parent_dir, help) @path = File.expand_path path, parent_dir @help = help end
Public Instance Methods
basename()
click to toggle source
# File lib/begin/path.rb, line 64 def basename File.basename @path end
contains?(path)
click to toggle source
# File lib/begin/path.rb, line 76 def contains?(path) path.to_str.start_with? @path end
copy_to(destination)
click to toggle source
# File lib/begin/path.rb, line 58 def copy_to(destination) ensure_exists destination.ensure_dir_exists FileUtils.cp @path, destination end
dir_contents()
click to toggle source
# File lib/begin/path.rb, line 43 def dir_contents escaped_path = @path.gsub(/[\\\{\}\[\]\*\?\.]/) { |x| '\\' + x } Dir.glob(File.join([escaped_path, '*'])) end
directory?()
click to toggle source
# File lib/begin/path.rb, line 68 def directory? File.directory? @path end
ensure_dir_exists()
click to toggle source
# File lib/begin/path.rb, line 37 def ensure_dir_exists ensure_exists return if directory? raise IOError, "#{@help} '#{@path}' is not a directory" end
ensure_exists()
click to toggle source
# File lib/begin/path.rb, line 26 def ensure_exists return if File.exist? @path raise IOError, "#{@help} '#{@path}' does not exist" end
ensure_symlink_exists()
click to toggle source
# File lib/begin/path.rb, line 31 def ensure_symlink_exists ensure_exists return if File.symlink? @path raise IOError, "#{@help} '#{@path}' is not a symbolic link" end
eql?(other)
click to toggle source
# File lib/begin/path.rb, line 10 def eql?(other) @path.eql?(other.to_str) end
exists?()
click to toggle source
# File lib/begin/path.rb, line 72 def exists? File.exist? @path end
hash()
click to toggle source
# File lib/begin/path.rb, line 14 def hash @path.hash end
make_dir()
click to toggle source
# File lib/begin/path.rb, line 48 def make_dir Dir.mkdir @path unless File.exist? @path ensure_dir_exists end
make_parent_dirs()
click to toggle source
# File lib/begin/path.rb, line 53 def make_parent_dirs parent = File.dirname @path FileUtils.mkdir_p parent end
to_s()
click to toggle source
# File lib/begin/path.rb, line 18 def to_s @path end
to_str()
click to toggle source
# File lib/begin/path.rb, line 22 def to_str @path end