Class: FalkorLib::CLI::Link

Inherits:
Thor
  • Object
show all
Includes:
FalkorLib::Common
Defined in:
lib/falkorlib/cli/link.rb

Overview

Thor class for symlink creation

Instance Method Summary collapse

Methods included from FalkorLib::Common

ask, bold, command?, cyan, error, exec_or_exit, execute, execute_in_dir, green, info, init_from_template, init_rvm, list_items, load_config, nice_execute, normalized_path, not_implemented, really_continue?, red, run, select_from, show_diff_and_write, store_config, warning, write_from_erb_template, write_from_template

Instance Method Details

#rootdir(dir = Dir.pwd) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/falkorlib/cli/link.rb', line 23

def rootdir(dir = Dir.pwd)
    raise FalkorLib::ExecError "Not used in a Git repository" unless FalkorLib::Git.init?
    path  = normalized_path(dir)
    relative_path_to_root = Pathname.new( FalkorLib::Git.rootdir(dir) ).relative_path_from Pathname.new( File.realpath(path))
    FalkorLib::Common.error "Already at the root directory of the Git repository" if "#{relative_path_to_root}" == "."
    target = options[:name] ? options[:name] : '.root'
    unless File.exists?( File.join(path, target))
        warning "creating the symboling link '#{target}' which points to '#{relative_path_to_root}'" if options[:verbose]
        # Format: ln_s(old, new, options = {}) -- Creates a symbolic link new which points to old.
         FileUtils.ln_s "#{relative_path_to_root}", "#{target}"
    end
end