class RBT::CheckForInvalidCurrentSymlinks

Public Class Methods

[](i = ARGV) click to toggle source
#
#
# File lib/rbt/utility_scripts/check_for_invalid_current_symlinks.rb, line 210
def self.[](i = ARGV)
  new(i)
end
new( i = nil, run_already = true ) click to toggle source
#

initialize

#
# File lib/rbt/utility_scripts/check_for_invalid_current_symlinks.rb, line 28
def initialize(
    i           = nil,
    run_already = true
  )
  reset
  set_input(i)
  run if run_already
end

Public Instance Methods

autocorrect_erroneous_entries() click to toggle source
#

autocorrect_erroneous_entries

#
# File lib/rbt/utility_scripts/check_for_invalid_current_symlinks.rb, line 115
def autocorrect_erroneous_entries
  _ = main_array?
  unless _.empty?
    _.each {|entry|
      opne "Next autocorrecting `#{sfancy(entry)}`."
      # =================================================================== #
      # First, determine the possible targets. One of these targets will
      # become our new main symlink.
      # =================================================================== #
      dirname = File.dirname(entry)
      possible_targets = Dir[dirname+'/*'].select {|line|
        File.basename(line) =~ /^\d+/
      }.sort_by {|line|
        File.basename(line)
      }.reverse
      this_target = possible_targets.first
      # =================================================================== #
      # Then, remove that directory.
      # =================================================================== #
      if File.directory? entry
        remove_directory(entry)
      end
      # =================================================================== #
      # Finally, set up the new symlink there. The old_target is the
      # current program version of the program in question, such
      # as "/Programs/Htop/2.0.2".
      # =================================================================== #
      old_target = this_target
      new_target = entry # This is the entry, yup.
      if File.exist? old_target
        symlink(old_target, new_target)
      else
        opnn; no_target_exists_at(old_target)
      end
    }
  end
end
discover_stuff()
inform_the_user_what_can_be_done_about_incorrect_entries() click to toggle source
#

inform_the_user_what_can_be_done_about_incorrect_entries

#
# File lib/rbt/utility_scripts/check_for_invalid_current_symlinks.rb, line 72
def inform_the_user_what_can_be_done_about_incorrect_entries
  opne "You can correct this by passing "\
       "#{orange('--autocorrect')} to this class."
end
input?() click to toggle source
#

input?

#
# File lib/rbt/utility_scripts/check_for_invalid_current_symlinks.rb, line 65
def input?
  @input
end
main_array?() click to toggle source
#

main_array?

#
# File lib/rbt/utility_scripts/check_for_invalid_current_symlinks.rb, line 108
def main_array?
  @array_these_entries_are_not_symlinks
end
menu(i) click to toggle source
#

menu (menu tag)

#
notify_the_user_that_everything_appears_to_be_fine() click to toggle source
#

notify_the_user_that_everything_appears_to_be_fine

#
# File lib/rbt/utility_scripts/check_for_invalid_current_symlinks.rb, line 168
def notify_the_user_that_everything_appears_to_be_fine
  opne 'Everything appears to be fine. The checked '
  opne "directory was `#{sdir(programs_dir?)}`"
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method RBT::LeanPrototype#reset
# File lib/rbt/utility_scripts/check_for_invalid_current_symlinks.rb, line 40
def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @array_these_entries_are_not_symlinks
  #
  # We collect all non-symlinks into the following Array.
  # ======================================================================= #
  @array_these_entries_are_not_symlinks = []
  discover_which_entries_are_not_symlinks # Fill up our main Array first, always.
end
run() click to toggle source
#

run (run tag)

#
# File lib/rbt/utility_scripts/check_for_invalid_current_symlinks.rb, line 198
def run
  show_which_entries_are_not_symlinks
  if main_array?.empty?
    notify_the_user_that_everything_appears_to_be_fine
  else
    inform_the_user_what_can_be_done_about_incorrect_entries
  end
end
set_input(i = '') click to toggle source
#

set_input

#
# File lib/rbt/utility_scripts/check_for_invalid_current_symlinks.rb, line 55
def set_input(i = '')
  i = i.first if i.is_a? Array
  i = i.to_s.dup
  @input = i
  menu(i)
end