class RBT::Action::ToCurrent

Public Class Methods

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

RBT::Action::ToCurrent[]

#
# File lib/rbt/actions/individual_actions/to_current/to_current.rb, line 312
def self.[](i = ARGV)
  new(i)
end
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
#

also_do_register_into_the_yaml_database?

#
# File lib/rbt/actions/individual_actions/to_current/to_current.rb, line 297
def also_do_register_into_the_yaml_database?
  @internal_hash[:also_do_register_into_the_yaml_database]
end
current_target?() click to toggle source
#

current_target?

This method will assemble the target residing under the /Programs hierarchy.

#
# File lib/rbt/actions/individual_actions/to_current/to_current.rb, line 248
def current_target?
  "#{programs_dir?}#{program_name?}/Current"
end
full_program_version_target?() click to toggle source
#

full_program_version_target?

This method is assumed to point to a directory.

#
# File lib/rbt/actions/individual_actions/to_current/to_current.rb, line 268
def full_program_version_target?
  "#{programs_dir?}#{program_name?.capitalize}/#{program_version?}/"
end
infer_the_program_version() click to toggle source
#

infer_the_program_version

#
# File lib/rbt/actions/individual_actions/to_current/to_current.rb, line 255
def infer_the_program_version
  _ = Dir[programs_dir?+program_name?+'/*'].select {|entry|
    File.directory? entry
  }.sort.reverse
  version = File.basename(_.first)
  return version
end
program_name?() click to toggle source
#

program_name?

#
# File lib/rbt/actions/individual_actions/to_current/to_current.rb, line 206
def program_name?
  @program_name
end
program_version?() click to toggle source
#

program_version?

#
# File lib/rbt/actions/individual_actions/to_current/to_current.rb, line 114
def program_version?
  @symlink_this_program_version
end
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
#

run (run tag)

#
# File lib/rbt/actions/individual_actions/to_current/to_current.rb, line 304
def run
  considering_deleting_the_current_symlink_if_it_exists
  do_create_the_new_symlink
end
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_program_version(i)