class RBT::Action::ToCurrent
Public Class Methods
[](i = ARGV)
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/actions/individual_actions/to_current/to_current.rb, line 42 def initialize( program_version = nil, run_already = true ) reset set_symlink_this_program_version(program_version.dup) # ======================================================================= # # === Handle blocks next # ======================================================================= # if block_given? yielded = yield case yielded # ===================================================================== # # === :do_not_register # ===================================================================== # when :do_not_register @internal_hash[:also_do_register_into_the_yaml_database] = false else if yielded.is_a? Hash # ================================================================= # # === :use_this_symlink_program_instance # ================================================================= # 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
also_do_register_into_the_yaml_database?()
click to toggle source
considering_deleting_the_current_symlink_if_it_exists()
click to toggle source
#¶ ↑
considering_deleting_the_current_symlink_if_it_exists
¶ ↑
#¶ ↑
# File lib/rbt/actions/individual_actions/to_current/to_current.rb, line 213 def considering_deleting_the_current_symlink_if_it_exists _ = current_target? # Get the symlink target. if File.symlink? _ orev "There already is a symlink at `#{sfile(_)}#{rev}`. "\ "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/actions/individual_actions/to_current/to_current.rb, line 225 def do_create_the_new_symlink # ======================================================================= # # Next, create a new symlink. # ======================================================================= # _ = current_target? # Get the symlink target. orev "Creating a new symlink at `#{sfile(_)}#{rev}`." new_target = full_program_version_target? orev "This symlink will point towards `#{sfile(new_target)}#{rev}`." 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
infer_the_program_version()
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::Action#reset
# File lib/rbt/actions/individual_actions/to_current/to_current.rb, line 78 def reset super() infer_the_namespace # ======================================================================= # # === :also_do_register_into_the_yaml_database # ======================================================================= # @internal_hash[:also_do_register_into_the_yaml_database] = true # ======================================================================= # # === @symlink_program_to_use # ======================================================================= # @symlink_program_to_use = RBT::SymlinkFromToCurrent.new(nil, :do_not_run_yet) set_program_name # Must initialize it at the least once. end
rnsymc( i = full_program_version_target? )
click to toggle source
#¶ ↑
rnsymc¶ ↑
This method delegates towards class RBT::SymlinkFromToCurrent
.
The argument to this method will default to a String such as:
/home/Programs/Python/3.8.3/
#¶ ↑
# File lib/rbt/actions/individual_actions/to_current/to_current.rb, line 282 def rnsymc( i = full_program_version_target? ) @symlink_program_to_use.set_use_this_program(i) if also_do_register_into_the_yaml_database? # Pass through in this case. else @symlink_program_to_use.do_not_register end @symlink_program_to_use.do_symlink 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/actions/individual_actions/to_current/to_current.rb, line 123 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. # ===================================================================== # _ = return_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/actions/individual_actions/to_current/to_current.rb, line 100 def set_symlink_program(i) # ======================================================================= # # We really set to the class that we want to use here, so the # next line is correct. # # We default to class RBT::SymlinkFromToCurrent since as of # April 2021. # ======================================================================= # @symlink_program_to_use = 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/actions/individual_actions/to_current/to_current.rb, line 150 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 # ======================================================================= # # === Counter how many '/' are in the given input # # Example: /home/Programs/Xev/1.2.4 # ======================================================================= # 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?) # ===================================================================== # # Example for splitted: # # ["home", "Programs", "Xev", "1.2.4"] # # ===================================================================== # use_this_program_name = splitted[-2] set_program_name(use_this_program_name) i = splitted[-1] end unless (i =~ /\d+/) # ===================================================================== # # Set the name of the program e. g. if we input only "python" here. # ===================================================================== # set_program_name(i) unless i.include? '/' i = infer_the_program_version # Must infer the version in this case. end @symlink_this_program_version = i end
Also aliased as: set_program_version