class RBT::CreateProgramVersionUrlFile

Constants

NAMESPACE
#

NAMESPACE

#

Public Class Methods

new( run_already = true ) { || ... } click to toggle source
#

initialize

#
# File lib/rbt/utility_scripts/create_program_version_url_file.rb, line 27
def initialize(
    run_already = true
  )
  reset
  if block_given?
    yielded = yield
    if yielded.is_a? Hash and
       yielded.has_key?(:show_last_update)
      @show_last_update = yielded.delete(:show_last_update)
    end
  end
  run if run_already
end

Public Instance Methods

iterate_over_the_expanded_cookbooks() click to toggle source
#

iterate_over_the_expanded_cookbooks

#
# File lib/rbt/utility_scripts/create_program_version_url_file.rb, line 140
def iterate_over_the_expanded_cookbooks
end
notify_the_user_that_we_require_the_expanded_cookbooks_directory() click to toggle source
#

notify_the_user_that_we_require_the_expanded_cookbooks_directory

#
# File lib/rbt/utility_scripts/create_program_version_url_file.rb, line 121
def notify_the_user_that_we_require_the_expanded_cookbooks_directory
  opnn; e 'Currently, the functionality to create '+teal('program')+
          ', '+teal('version')+' and '+teal('URL')+', into'
  opnn; e 'a single .txt file, depends on the expanded '\
          'cookbook dataset.'
  e
  opnn; e 'This dataset should normally reside at '+
           sdir(@directory_expanded_cookbooks)+'.'
  opnn; e 'This directory does not exist, so the dataset is unavailable.'
  e
  opnn; e 'You can generate the dataset anew via:'
  e
  opnn; e '  rbt --expand'
  e
end
obtain_the_expanded_cookbooks() click to toggle source
#

obtain_the_expanded_cookbooks

#
# File lib/rbt/utility_scripts/create_program_version_url_file.rb, line 56
def obtain_the_expanded_cookbooks
  newline = "\n".dup
  # ======================================================================= #
  # We read the individual, expanded .yml files from there and only
  # store the relevant parts into the Array called @array_to_be_stored.
  # ======================================================================= #
  if expanded_cookbooks_directory_exists?
    @all_expanded_cookbooks = Dir["#{@directory_expanded_cookbooks}*.yml"].sort
    @all_expanded_cookbooks.each {|yaml_file|
      dataset = YAML.load_file(yaml_file)
      program_name    = File.basename(yaml_file.sub(/\.yml$/,''))
      program_version = dataset['program_version']
      program_url     = dataset['url1']
      @array_to_be_stored << [
        program_name, program_version, program_url
      ]
      if @show_last_update
        # ================================================================= #
        # In this case, append more information.
        # ================================================================= #
        last_update = dataset['last_update']
        @array_to_be_stored[-1] << last_update 
      end
    }
    # ===================================================================== #
    # Now that we have populated @array_to_be_stored, we must
    # use it to create a .txt file.
    # ===================================================================== #
    what = ''.dup
    @array_to_be_stored.each {|entry|
      program_name, program_version, program_url = entry[0], entry[1], entry[2]
      if @show_last_update
        last_update = entry[3] # It is the last element.
      end
      # =================================================================== #
      # Add what we need here - name of the program, the version and
      # the remote URL. This will be properly padded.
      # =================================================================== #
      what << program_name.to_s.ljust(28)+
              program_version.to_s.ljust(22)
      # =================================================================== #
      # Append when the last update happened, if we use that entry at
      # all.
      # =================================================================== #
      if @show_last_update
        what << last_update.to_s.strip.ljust(14)
      end
      # =================================================================== #
      # Next, append the remote URL to the line.
      # =================================================================== #
      what << program_url.to_s.rstrip.ljust(44).rstrip+
              newline
    }
    into = "#{RBT.log_dir?}CookbookDirectory/programs_version_url.txt"
    opn; e 'Now storing into `'+sfile(into)+'`.'
    create_directory_if_it_does_not_yet_exist(File.dirname(into))
    write_what_into(what, into)
  else
    notify_the_user_that_we_require_the_expanded_cookbooks_directory
  end
end
reset() click to toggle source
#

reset

#
Calls superclass method RBT::Base#reset
# File lib/rbt/utility_scripts/create_program_version_url_file.rb, line 44
def reset
  super()
  @directory_expanded_cookbooks = RBT.directory_expanded_cookbooks?
  @all_expanded_cookbooks = []
  @show_last_update = false
  @array_to_be_stored = []
  @namespace = NAMESPACE
end
run() click to toggle source
#

run

#
# File lib/rbt/utility_scripts/create_program_version_url_file.rb, line 146
def run
  obtain_the_expanded_cookbooks
  iterate_over_the_expanded_cookbooks
end