class RBT::Cookbooks::CheckForAvailableVersions
Constants
- DEFAULT_PROGRAM
#¶ ↑
DEFAULT_PROGRAM
¶ ↑#¶ ↑
Public Class Methods
new( for_this_program = nil, run_already = true ) { || ... }
click to toggle source
#¶ ↑
initialize¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/check_for_available_versions.rb, line 33 def initialize( for_this_program = nil, run_already = true, &block ) reset set_seek_this_program( for_this_program ) case run_already # === :dont_run_yet when :dont_run_yet, :do_not_run_yet run_already = false when :be_verbose be_verbose run_already = true end # ======================================================================= # # === Handle blocks next # ======================================================================= # if block_given? yielded = yield case yielded when :be_verbose be_verbose end end run if run_already end
Public Instance Methods
cleanup()
click to toggle source
#¶ ↑
cleanup¶ ↑
We will get rid of two instance variables here.
#¶ ↑
# File lib/rbt/utility_scripts/check_for_available_versions.rb, line 124 def cleanup if self.instance_variable_defined? :@sanitize_cookbook_dataset remove_instance_variable(:@sanitize_cookbook_dataset) # Trying this. end if self.instance_variable_defined? :@data remove_instance_variable(:@data) end end
feedback_matches()
click to toggle source
#¶ ↑
feedback_matches
¶ ↑
This method is not needed if @be_silent is set to false.
We will feedback the matches that we found (which were stored in @results).
#¶ ↑
# File lib/rbt/utility_scripts/check_for_available_versions.rb, line 229 def feedback_matches if @results.empty? opne 'No locally available version has been found.' else e print rev cliner @results.each_with_index { |_, index| index += 1 index = '%02s' % (index) if @results.size > 9 e " #{rev}(#{simp(index.to_s)}#{rev}) #{sdir(_)}" } cliner e end end
Also aliased as: feedback_available_versions
fetch_entry_at_this_position(i)
click to toggle source
#¶ ↑
fetch_entry_at_this_position
¶ ↑
If the argument passed to this method, ‘i`, is called “first” then we equal this to be the first entry listed in the array @results.
If the argument passed is however called “last”, then it will default to the last entry of that array.
We also have to ensure that input like “-3” is valid. -3 would translate to “give me the version minus 3. ”-1“ would say ”give me the entry that comes last“.
#¶ ↑
# File lib/rbt/utility_scripts/check_for_available_versions.rb, line 146 def fetch_entry_at_this_position(i) if @results.empty? obtain_all_entries_from_the_source_directory(seek?) end i = i.to_s.dup # Need to work on a copy here. case i # Handle the two keywords 'first' and 'last' here. when 'first','vnewest','newest' i = 1.to_s when 'last','vlatest','latest' i = @results.size.to_s end i[0,1] = '' if i.start_with? 'v' # Get rid of "v", should it exist. # ========================================================================= # # Handle negative input next. # ========================================================================= # if i.to_s.include? '-' # account for a negative number. i = (@results.size - i.to_i.abs + 1) # +1 since Jan 2012. end i = i.to_i i = 1 if i <= 0 # ========================================================================= # # Hardcap to a proper size. @results must exist for this to work though. # ========================================================================= # i = @results.size if i > @results.size result = @results[i - 1] set_version(ProgramInformation.return_version(result)) return result end
Also aliased as: position_at
obtain_all_entries_from_the_source_directory( seek_this_program = seek? )
click to toggle source
#¶ ↑
obtain_all_entries_from_the_source_directory
¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/check_for_available_versions.rb, line 203 def obtain_all_entries_from_the_source_directory( seek_this_program = seek? ) target_directory = "#{source_directory?}#{seek_this_program}/" @results = Dir[target_directory+'*'] sort_results @results = @results.reverse # Keep it reverse-sorted. return @results end
reset()
click to toggle source
#¶ ↑
reset¶ ↑
#¶ ↑
Calls superclass method
RBT::LeanPrototype#reset
# File lib/rbt/utility_scripts/check_for_available_versions.rb, line 66 def reset super() infer_the_namespace # ======================================================================= # # === @seek_this_program # ======================================================================= # @seek_this_program = nil # ======================================================================= # # === :be_verbose # ======================================================================= # set_be_quiet # by default the class is silent and less verbose. # ======================================================================= # # === @version # ======================================================================= # @version = nil # This variable is only set via a special method. # ======================================================================= # # === @results # ======================================================================= # @results = [] end
results?()
click to toggle source
run()
click to toggle source
#¶ ↑
run (run tag)¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/check_for_available_versions.rb, line 250 def run obtain_all_entries_from_the_source_directory cleanup feedback_matches if be_verbose? or debug? end
Also aliased as: check_for_program
seek?()
click to toggle source
set_seek_this_program(i = DEFAULT_PROGRAM)
click to toggle source
#¶ ↑
set_seek_this_program
¶ ↑
This method simply sets an instance variable that will designate our main program to use or search for.
#¶ ↑
# File lib/rbt/utility_scripts/check_for_available_versions.rb, line 181 def set_seek_this_program(i = DEFAULT_PROGRAM) i = i.join if i.is_a? Array i = DEFAULT_PROGRAM if i.nil? i = i.to_s.dup # Keep a copy. if i.include?('-') or i.include?('_') i = ProgramInformation.return_name(i) end i.chop! if i.end_with? '-' # Also get rid of trailing '-' chars. @seek_this_program = i end
Also aliased as: set_program
set_version(i)
click to toggle source
sort_results()
click to toggle source
try_to_find(this)
click to toggle source