class Cookbooks::CheckForAvailableVersions

Constants

DEFAULT_PROGRAM
#

DEFAULT_PROGRAM

#
NAMESPACE
#

NAMESPACE

#

Public Class Methods

new( for_this_program = nil, run_already = true ) click to toggle source
#

initialize

#
Calls superclass method
# File lib/cookbooks/utility_scripts/check_for_available_versions.rb, line 38
def initialize(
    for_this_program = nil,
    run_already      = true
  )
  super()
  reset
  set_seek_this_program(for_this_program)
  case run_already
  when :dont_run_yet, :do_not_run_yet
    run_already = false
  when :be_verbose
    be_verbose
    run_already = true
  end
  run if run_already
end

Public Instance Methods

available_versions()
Alias for: version?
check_for_program()
Alias for: run
cleanup() click to toggle source
#

cleanup

We will get rid of two instance variables here.

#
# File lib/cookbooks/utility_scripts/check_for_available_versions.rb, line 101
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
data?()
Alias for: results?
feedback_available_versions()
Alias for: feedback_matches
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/cookbooks/utility_scripts/check_for_available_versions.rb, line 125
def feedback_matches
  if @results.empty?
    opnn; e 'Sorry, found none.'
  else
    cliner
    @results.each_with_index { |_, index|
      index += 1
      index  = '%02s' % (index) if @results.size > 9
      e '  ('+simp(index.to_s)+') '+sdir(_) 
    }; cliner
  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/cookbooks/utility_scripts/check_for_available_versions.rb, line 159
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
input?()
Alias for: seek?
obtain_all_entries_from_the_source_directory( seek_this_program = seek? ) click to toggle source
#

#obtain_all_entries_from_the_source_directory

#
# File lib/cookbooks/utility_scripts/check_for_available_versions.rb, line 216
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
opnn() click to toggle source
#

opnn

#
Calls superclass method Cookbooks::Base#opnn
# File lib/cookbooks/utility_scripts/check_for_available_versions.rb, line 113
def opnn
  super(NAMESPACE)
end
position_at(i)
program?()
Alias for: seek?
programs?()
Alias for: results?
reset() click to toggle source
#

reset

#
Calls superclass method Cookbooks::Base#reset
# File lib/cookbooks/utility_scripts/check_for_available_versions.rb, line 58
def reset
  super()
  @be_verbose = false # on default we are silent and less verbose.
  @version = nil # This variable is only set via a special method.
  @results = []
end
results?() click to toggle source
#

data?

#
# File lib/cookbooks/utility_scripts/check_for_available_versions.rb, line 208
def results?
  @results # This should be changed perhaps.
end
Also aliased as: data?, programs?
run() click to toggle source
#

run (run tag)

#
# File lib/cookbooks/utility_scripts/check_for_available_versions.rb, line 229
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
#

seek?

#
# File lib/cookbooks/utility_scripts/check_for_available_versions.rb, line 68
def seek?
  @seek_this_program
end
Also aliased as: program?, input?
set_program(i = DEFAULT_PROGRAM)
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/cookbooks/utility_scripts/check_for_available_versions.rb, line 194
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
#

#set_version

#
# File lib/cookbooks/utility_scripts/check_for_available_versions.rb, line 91
def set_version(i)
  i = i.gsub(/\.tar\.bz2$/,'').gsub(/\.gz$/,'')
  @version = i
end
sort_results() click to toggle source
#

#sort_results

#
# File lib/cookbooks/utility_scripts/check_for_available_versions.rb, line 76
def sort_results
  @results = @results.sort # Or we can use this: .sort_by { |key| key.scan(/\d+/).map {|x| x.to_i } }.reverse
end
try_to_find(this) click to toggle source
#

#try_to_find

#
# File lib/cookbooks/utility_scripts/check_for_available_versions.rb, line 141
def try_to_find(this)
  set_program(this)
  run
end
version()
Alias for: version?
version?() click to toggle source
#

version?

#
# File lib/cookbooks/utility_scripts/check_for_available_versions.rb, line 83
def version?
  @version
end
Also aliased as: version, available_versions