class RBT::VersionSwitcher
Constants
- NAMESPACE
#¶ ↑
NAMESPACE
¶ ↑#¶ ↑
Public Class Methods
[](i = '')
click to toggle source
new( commandline_arguments = ARGV, run_already = true ) { || ... }
click to toggle source
#¶ ↑
initialize¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/version_switcher.rb, line 31 def initialize( commandline_arguments = ARGV, run_already = true ) reset set_commandline_arguments(commandline_arguments) if block_given? yielded = yield case yielded when :be_quiet be_quiet when :be_quiet_and_do_not_registered be_quiet @do_not_register = true end end run if run_already end
Public Instance Methods
determine_the_available_program_versions()
click to toggle source
#¶ ↑
determine_the_available_program_versions
¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/version_switcher.rb, line 126 def determine_the_available_program_versions target = "#{programs_dir?}#{program_name?}/*" @array_available_program_versions = Dir[target].select {|entry| File.directory?(entry) }.select {|line| line =~ /\d+/ # Only obtain numbers. } end
program_name?()
click to toggle source
program_version?()
click to toggle source
report_the_current_version_in_use()
click to toggle source
#¶ ↑
report_the_current_version_in_use
¶ ↑
This method will simply report the current program version in use.
#¶ ↑
# File lib/rbt/utility_scripts/version_switcher.rb, line 153 def report_the_current_version_in_use _ = return_current_program_version if _.nil? opnn; e 'No current program version could be determined.' else opnn; e 'The current program version for the program '+ sfancy(program_name?.downcase)+' in use is: '+ sfancy(_) end end
reset()
click to toggle source
#¶ ↑
reset (reset tag)¶ ↑
#¶ ↑
Calls superclass method
RBT::Base#reset
# File lib/rbt/utility_scripts/version_switcher.rb, line 53 def reset super() @do_not_register = false # By default, register into the yaml database. # ======================================================================= # # The following Array will keep track of the possible python versions. # ======================================================================= # @array_available_program_versions = [] # ======================================================================= # # If the user wants a program version then this variable can be of help. # ======================================================================= # @program_version = nil @namespace = NAMESPACE end
return_current_program_version()
click to toggle source
return_path_to_current()
click to toggle source
#¶ ↑
return_path_to_current
¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/version_switcher.rb, line 167 def return_path_to_current programs_dir?+program_name?+'/Current' end
Also aliased as: path_to_current
return_program_version_of( i = File.readlink(path_to_current) )
click to toggle source
run()
click to toggle source
#¶ ↑
run (run tag)¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/version_switcher.rb, line 283 def run # ======================================================================= # # First, obtain all available program versions. # ======================================================================= # determine_the_available_program_versions try_to_report_which_program_versions_appear_to_be_available end
set_commandline_arguments(i)
click to toggle source
#¶ ↑
set_commandline_arguments
¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/version_switcher.rb, line 77 def set_commandline_arguments(i) i = [i].flatten.compact # <- We need an Array. @commandline_arguments = i # ======================================================================= # # We will assume that the first argument given ^^^ is the # name of the program at hand. # ======================================================================= # program_name = @commandline_arguments.first set_program_name(program_name) if @commandline_arguments.size > 1 set_program_version(@commandline_arguments[1]) end end
set_program_name( i = Dir.pwd )
click to toggle source
#¶ ↑
set_program_name
¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/version_switcher.rb, line 101 def set_program_name( i = Dir.pwd ) i = i.join(' ').strip if i.is_a? Array case i when :default, nil i = Dir.pwd end i = i.to_s.dup i = File.basename(i) if i.include? '/' i.capitalize! @program_name = i menu(i) end
set_program_version(i)
click to toggle source
show_help()
click to toggle source
to_current( the_other_version )
click to toggle source
#¶ ↑
to_current
¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/version_switcher.rb, line 221 def to_current( the_other_version ) opnn; e "Now switching to the version `#{sfile(the_other_version)}`." if @do_not_register RBT::ToCurrent.new(the_other_version) { :do_not_register } else RBT::ToCurrent.new(the_other_version) end end
try_to_pick_that_particular_program_version(i)
click to toggle source
try_to_report_which_program_versions_appear_to_be_available()
click to toggle source
#¶ ↑
try_to_report_which_program_versions_appear_to_be_available
¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/version_switcher.rb, line 244 def try_to_report_which_program_versions_appear_to_be_available # ======================================================================= # # Now we have all available program versions. We must first present to # the user which versions are available. # ======================================================================= # _ = @array_available_program_versions unless _.empty? opnn; e 'These program versions appear to be available:' e sorted = _.sort_by {|entry| entry.to_s } # Better to keep it sorted. sorted.each {|entry| version = File.basename(entry).to_s e sfancy(" #{version}") }; e report_the_current_version_in_use if program_version? # =================================================================== # # In this case, try to pick that particular program version. # =================================================================== # try_to_pick_that_particular_program_version(program_version?) return end # ===================================================================== # # Next, switch to the other version; this works only if we have # exactly two elements. # ===================================================================== # if _.size == 2 the_other_version = _.reject {|line| line.include? return_current_program_version } the_other_version = the_other_version.first if the_other_version.is_a? Array to_current(the_other_version) end end end