class RBT::SymlinkAllUpcasedProgramsToDowncasedVariants

Constants

NAMESPACE
#

NAMESPACE

#

Public Class Methods

[](i = '') click to toggle source
#

[]

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

initialize

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

Public Instance Methods

check_these_entries_for_upcased_program_names(i) click to toggle source
#

check_these_entries_for_upcased_program_names

#
# File lib/rbt/utility_scripts/symlink_all_upcased_programs_to_downcased_variants.rb, line 77
def check_these_entries_for_upcased_program_names(i)
  if i.empty?
    do_notify_the_user_that_no_program_was_symlinked
  else
    i.each {|entry|
      dirname = File.basename(entry)
      dirname[0,1] = dirname[0,1].upcase
      downcased_variant = dirname.downcase
      downcased_variant[0,1] = downcased_variant[0,1].upcase
      if dirname == downcased_variant # Then all is fine.
      else
        @n_programs_were_modified += 1
        opnn; e 'Found an upcased program name: '+sfancy(entry)
        properly_downcase_this_program(entry)
      end
    }
  end
  if @n_programs_were_modified and !i.empty?
    do_notify_the_user_that_no_program_was_symlinked
  end
end
do_notify_the_user_that_no_program_was_symlinked() click to toggle source
#

do_notify_the_user_that_no_program_was_symlinked

#
# File lib/rbt/utility_scripts/symlink_all_upcased_programs_to_downcased_variants.rb, line 118
def do_notify_the_user_that_no_program_was_symlinked
  opnn; e 'No program was symlinked. This either means that you have had'
  opnn; e "no entry under #{sfancy(programs_dir?)}, that you have "\
          "had no program that could"
  opnn; e 'be symlinked to its non-upcased variant, or that all programs '\
          'that'
  opnn; e 'had an upcased variant were already symlinked.' 
end
input?() click to toggle source
#

input?

#
# File lib/rbt/utility_scripts/symlink_all_upcased_programs_to_downcased_variants.rb, line 60
def input?
  @input
end
properly_downcase_this_program(real_existing_name) click to toggle source
#

properly_downcase_this_program

This is the action that will do the correct symlink-operation.

#
# File lib/rbt/utility_scripts/symlink_all_upcased_programs_to_downcased_variants.rb, line 104
def properly_downcase_this_program(real_existing_name)
  dirname  = File.dirname(real_existing_name)
  basename = File.basename(real_existing_name).downcase
  basename[0,1] = basename[0,1].upcase
  new_name = File.join(dirname, basename)
  new_name.delete!('-') if new_name.include? '-'
  opnn; e "Symlinking `#{sfancy(real_existing_name)}"\
          "` towards `#{sfancy(new_name)}`."
  symlink(real_existing_name, new_name) { :be_quiet }
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method RBT::Base#reset
# File lib/rbt/utility_scripts/symlink_all_upcased_programs_to_downcased_variants.rb, line 42
def reset
  super()
  @namespace = NAMESPACE
  @n_programs_were_modified = 0
end
run() click to toggle source
#

run (run tag)

#
# File lib/rbt/utility_scripts/symlink_all_upcased_programs_to_downcased_variants.rb, line 67
def run
  all_program_entries = Dir["#{programs_dir?}*"].select {|entry|
    File.directory? entry
  }
  check_these_entries_for_upcased_program_names(all_program_entries)
end
set_input(i = '') click to toggle source
#

set_input

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