class RBT::ToCurrent
Constants
- NAMESPACE
#¶ ↑
NAMESPACE
¶ ↑#¶ ↑
Public Class Methods
[](i = '')
click to toggle source
new( program_version = nil, run_already = true ) { || ... }
click to toggle source
#¶ ↑
initialize¶ ↑
The input to this method should be a String such as “/Programs/Python/3.6.2/”.
#¶ ↑
# File lib/rbt/utility_scripts/to_current.rb, line 39 def initialize( program_version = nil, run_already = true ) reset set_symlink_this_program_version(program_version) if block_given? yielded = yield case yielded when :do_not_register @also_do_register_into_the_yaml_database = false else if yielded.is_a? Hash if yielded.has_key? :use_this_symlink_program_instance set_symlink_program(yielded.delete(:use_this_symlink_program_instance)) end end end end run if run_already end
Public Instance Methods
considering_deleting_the_current_symlink_if_it_exists()
click to toggle source
#¶ ↑
considering_deleting_the_current_symlink_if_it_exists
¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/to_current.rb, line 186 def considering_deleting_the_current_symlink_if_it_exists _ = current_target? # Get the symlink target. if File.symlink? _ opnn; e "There already is a symlink at `#{sfile(_)}`. "\ "It will be removed next." delete(_) end end
current_target?()
click to toggle source
do_create_the_new_symlink()
click to toggle source
#¶ ↑
do_create_the_new_symlink
¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/to_current.rb, line 198 def do_create_the_new_symlink # ======================================================================= # # Next, create a new symlink. # ======================================================================= # _ = current_target? # Get the symlink target. opnn; e "Creating a new symlink at `#{sfile(_)}`." new_target = full_program_version_target? opnn; e "This symlink will point towards `#{sfile(new_target)}`." if File.directory? new_target symlink(program_version?, _) # ===================================================================== # # Consider invoking rnsymc as well. # ===================================================================== # rnsymc(new_target) end end
full_program_version_target?()
click to toggle source
program_name?()
click to toggle source
program_version?()
click to toggle source
reset()
click to toggle source
#¶ ↑
reset (reset tag)¶ ↑
#¶ ↑
Calls superclass method
RBT::Base#reset
# File lib/rbt/utility_scripts/to_current.rb, line 64 def reset super() set_program_name # Must initialize it at the least once. @also_do_register_into_the_yaml_database = true @symlink_program = RBT::SymlinkThisProgram.new(nil, :do_not_run_yet) @namespace = NAMESPACE end
rnsymc( i = full_program_version_target? )
click to toggle source
#¶ ↑
rnsymc¶ ↑
This method delegates towards class RBT::SymlinkThisProgram
.
#¶ ↑
# File lib/rbt/utility_scripts/to_current.rb, line 220 def rnsymc( i = full_program_version_target? ) @symlink_program.set_use_this_program(i) if @also_do_register_into_the_yaml_database # pass through in this case else @symlink_program.do_not_register end @symlink_program.run end
run()
click to toggle source
set_program_name(i = nil)
click to toggle source
#¶ ↑
set_program_name
¶ ↑
The setter of the program name.
#¶ ↑
# File lib/rbt/utility_scripts/to_current.rb, line 96 def set_program_name(i = nil) i = i.first if i.is_a? Array if i.nil? # ===================================================================== # # In this case, we will try to obtain the program name from # the target directory. # ===================================================================== # _ = Dir.pwd if _.include? programs_dir? and (_.count('/') > 1) i = _ end end i = i.to_s.dup i = File.basename(i) if i.include? '/' i.capitalize! @program_name = i end
set_symlink_program(i)
click to toggle source
#¶ ↑
set_symlink_program
¶ ↑
This method can be used to assign towards the symlink-program that will be used. For example, class RBT::Compile
can pass its own modified variant into this method here, thus being able to control what class RBT::ToCurrent
is doing at the symlink-progam step.
#¶ ↑
# File lib/rbt/utility_scripts/to_current.rb, line 80 def set_symlink_program(i) @symlink_program = i end
set_symlink_this_program_version(i)
click to toggle source
#¶ ↑
set_symlink_this_program_version
¶ ↑
This setter keeps track of the particular program version that we will use. For example, if we have an input such as “/Programs/Python/3.6.2”, then the program_version will be 3.6.2.
#¶ ↑
# File lib/rbt/utility_scripts/to_current.rb, line 123 def set_symlink_this_program_version(i) i = i.first if i.is_a? Array # ======================================================================= # # === Safeguard against nil-entries # ======================================================================= # if i.nil? # fetch random entry entries = Dir['*'] # Fetch all entries first. if entries.size > 1 # Try to find a number i = entries.select {|line| line =~ /\d+/ }.first else i = entries.first end end # ======================================================================= # # === Get rid of trailing '/' tokens. # ======================================================================= # if i.end_with? '/' i = i.dup if i.frozen? i.chop! end if i.include? programs_dir? and (i =~ /\d+/) and (i.count('/') > 1) # Has more than one '/' token. # ===================================================================== # # In this case, we assume that the user has input something # such as "/Programs/Python/3.6.2". # ===================================================================== # splitted = i.split('/').reject(&:empty?) set_program_name(splitted[1]) i = splitted[2] end @symlink_this_program_version = i end
Also aliased as: set_program_version