class RBT::RemoveSymlinks

Constants

ARRAY_DIRECTORIES_TO_CHECK
#

ARRAY_DIRECTORIES_TO_CHECK

#
DEFAULT_MODE
#

DEFAULT_MODE

#
SHALL_WE_CREATE_MISSING_DIRECTORIES
#

SHALL_WE_CREATE_MISSING_DIRECTORIES

This may create missing directories.

#

Public Class Methods

[](i = '') click to toggle source
#
#
# File lib/rbt/utility_scripts/remove_symlinks.rb, line 288
def self.[](i = '')
  new(i)
end
new( mode = :gobolinux_mode, run_already = true ) click to toggle source
#

initialize

#
# File lib/rbt/utility_scripts/remove_symlinks.rb, line 55
def initialize(
    mode        = :gobolinux_mode,
    run_already = true
  )
  reset
  set_mode(mode)
  run if run_already
end

Public Instance Methods

consider_using_other_directories() click to toggle source
#

consider_using_other_directories

#
# File lib/rbt/utility_scripts/remove_symlinks.rb, line 178
def consider_using_other_directories
  case @mode
  when 'HERE','PWD','pwd' # This allows us to work on the current directory instead.
    @array_directories_to_check[0,0] = return_pwd
  end unless File.exist? @mode
end
default()
Alias for: run
process_each_directory( i = @array_directories_to_check ) click to toggle source
#

process_each_directory

#
# File lib/rbt/utility_scripts/remove_symlinks.rb, line 105
def process_each_directory(
    i = @array_directories_to_check
  )
  unless i.is_a? Array
    i = [i]
  end 
  i.each {|entry|
    unless File.exist? entry
      if SHALL_WE_CREATE_MISSING_DIRECTORIES
        opnwarn 'The directory `'+sdir(entry)+swarn('` does not exist.')
        opnwarn 'Thus, we will create it now.'
        create_directory(entry)
      end
    end
    # ===================================================================== #
    # Next, obtain all symlinks from the target.
    # ===================================================================== #
    _ = get_all_symlinks_from(entry)
    _.each {|inner_entry|
      if File.exist? inner_entry # File exist, this is good, passthrough.
      else # The file does not exist, so register it for removal.
        # e 'FILE DOES NOT EXIST '+sfile(inner_entry)
        opne sfile(inner_entry)+' does not exist.'
        opne "→ Thus we delete `#{sfile(inner_entry)}`."
        register_broken_symlink_for_removal(inner_entry) # First register, then delete.
      end
    }
  }
end
remove_empty_directories() click to toggle source
#

remove_empty_directories

#
# File lib/rbt/utility_scripts/remove_symlinks.rb, line 168
def remove_empty_directories
  # ======================================================================= #
  # Delegate towards class RBT::RemoveEmptyDirectories next:
  # ======================================================================= #
  RemoveEmptyDirectories.new
end
reset() click to toggle source
#

reset

#
Calls superclass method RBT::Base#reset
# File lib/rbt/utility_scripts/remove_symlinks.rb, line 67
def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @array_directories_to_check
  # ======================================================================= #
  @array_directories_to_check = ARRAY_DIRECTORIES_TO_CHECK
  # ======================================================================= #
  # === @array_remove_these_broken_symlinks
  # ======================================================================= #
  @array_remove_these_broken_symlinks = []
  # ======================================================================= #
  # === :be_verbose
  # ======================================================================= #
  set_be_quiet
end
run() click to toggle source
#

run (run tag)

#
# File lib/rbt/utility_scripts/remove_symlinks.rb, line 276
def run
  consider_using_other_directories
  remove_empty_directories
  process_each_directory
  remove_broken_symlinks
  notify_the_user_how_many_symlinks_were_removed
end
Also aliased as: start, default
set_base_dir(i) click to toggle source
#

set_base_dir

#
# File lib/rbt/utility_scripts/remove_symlinks.rb, line 87
def set_base_dir(i)
  i = rds(i)
  i << '/' unless i.end_with? '/' # We require a trailing '/' here.
  @base_dir = i
end
set_mode( i = DEFAULT_MODE ) click to toggle source
#

set_mode

Not yet sure if we need this.

#
# File lib/rbt/utility_scripts/remove_symlinks.rb, line 226
def set_mode(
    i = DEFAULT_MODE
  )
  if i.is_a? Array
    i = i.first
  end
  i = DEFAULT_MODE if i.nil?
  case i # case tag
  # ======================================================================= #
  # === remove_symlinks --pwd
  #
  # This entry point will use the current working directory as our
  # input-base.
  # ======================================================================= #
  when /^-?-?pwd$/,
       /^-?-?remove(-|_)?all(-|_)?symlinks$/
    remove_these_symlinks(Dir['*'], :be_verbose)
    exit
  # ======================================================================= #
  # === remove_symlinks --help
  # ======================================================================= #
  when /^-?-?help$/
    show_help
    exit
  end
  @mode = i.to_s # Will be guaranteed to be a String.
end
show_help() click to toggle source
#

show_help (help tag)

To invoke this method, try:

remove_symlinks --help
#
# File lib/rbt/utility_scripts/remove_symlinks.rb, line 193
def show_help
  opnn { :no_trailing_character }
  e
  e
  e '  --remove-all-symlinks # Remove all symlinks in '\
    'the current directory.'
  e '  --pwd                 # ^^^ an alias to the above'
  e
end
start()
Alias for: run