class RBT::VersionSwitcher
Public Class Methods
[](i = ARGV)
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 27 def initialize( commandline_arguments = ARGV, run_already = true ) reset set_commandline_arguments( commandline_arguments ) # ======================================================================= # # === Handle blocks given to this class # ======================================================================= # if block_given? yielded = yield case yielded # ===================================================================== # # === :be_quiet # ===================================================================== # when :be_quiet be_quiet # ===================================================================== # # === :be_quiet_and_do_not_registered # ===================================================================== # 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 142 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 171 def report_the_current_version_in_use _ = return_current_program_version if _.nil? opne 'No current program version could be determined.' else opne rev+'The current program version for the program '+ sfancy(program_name?.downcase)+ rev+' in use is: '+ sfancy(_) end end
reset()
click to toggle source
#¶ ↑
reset (reset tag)¶ ↑
#¶ ↑
Calls superclass method
RBT::LeanPrototype#reset
# File lib/rbt/utility_scripts/version_switcher.rb, line 60 def reset super() infer_the_namespace # ======================================================================= # # === @do_not_register # # By default, register into the yaml database. # ======================================================================= # @do_not_register = false # ======================================================================= # # === @array_available_program_versions # # The following Array will keep track of the possible python versions. # ======================================================================= # @array_available_program_versions = [] # ======================================================================= # # === @program_version # # If the user wants a program version then this variable can be of help. # ======================================================================= # @program_version = nil 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 186 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 303 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 93 def set_commandline_arguments(i) i = [i].flatten.compact # <- We need an Array. @internal_hash[:commandline_arguments] = i # ======================================================================= # # We will assume that the first argument given ^^^ is the # name of the program at hand. # ======================================================================= # program_name = @internal_hash[:commandline_arguments].first set_program_name(program_name) if @internal_hash[:commandline_arguments].size > 1 set_program_version(@internal_hash[:commandline_arguments][1]) end end
set_program_name( i = return_pwd )
click to toggle source
#¶ ↑
set_program_name
¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/version_switcher.rb, line 117 def set_program_name( i = return_pwd ) i = i.join(' ').strip if i.is_a? Array case i when :default, nil i = return_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 241 def to_current( the_other_version ) orev "Now switching to the version `#{sfile(the_other_version)}#{rev}`." if @do_not_register action(:ToCurrent, the_other_version) { :do_not_register } else action(:ToCurrent, 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 264 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? orev '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 efancy " #{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