Module: TTY::PathHelpers

Included in:
Cmd, Commands::Add, Templater
Defined in:
lib/tty/path_helpers.rb

Instance Method Summary collapse

Instance Method Details

#name_from_path(path) ⇒ Object

Extract name from a path



24
25
26
# File 'lib/tty/path_helpers.rb', line 24

def name_from_path(path)
  Pathname(path).basename.to_s
end

#relative_path_from(root_path, path) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Extract a relative path for the app



31
32
33
34
35
# File 'lib/tty/path_helpers.rb', line 31

def relative_path_from(root_path, path)
  project_path = Pathname.new(path)
  return project_path if project_path.relative?
  project_path.relative_path_from(root_path)
end

#root_pathPathname

The root path of the app running this command

Returns:

  • (Pathname)


10
11
12
# File 'lib/tty/path_helpers.rb', line 10

def root_path
  @root_path ||= Pathname.pwd
end

#within_root_path(&block) ⇒ Object

Execute command within root path



17
18
19
# File 'lib/tty/path_helpers.rb', line 17

def within_root_path(&block)
  Dir.chdir(root_path, &block)
end