class RBT::CreateProgramVersionUrlFile

Public Class Methods

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

initialize

#
# File lib/rbt/information/create_program_version_url_file.rb, line 22
def initialize(
    run_already = true
  )
  reset
  # ======================================================================= #
  # === Handle blocks next
  # ======================================================================= #
  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

array_to_be_stored?() click to toggle source
#

array_to_be_stored?

#
# File lib/rbt/information/create_program_version_url_file.rb, line 187
def array_to_be_stored?
  @array_to_be_stored
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/information/create_program_version_url_file.rb, line 158
def notify_the_user_that_we_require_the_expanded_cookbooks_directory
  opne 'Currently, the functionality to create '+teal('program')+
       ', '+teal('version')+' and '+teal('URL')+', into'
  opne 'a single .md file, depends on the expanded '\
       'cookbook dataset.'
  e
  opne "This dataset should normally reside at "\
       "#{sdir(@directory_expanded_cookbooks)}."
  opne 'This directory does not exist, so the dataset is unavailable.'
  e
  opne 'You can generate the dataset anew via:'
  e
  opne '  rbt --expand'
  e
end
obtain_the_expanded_cookbooks() click to toggle source
#

obtain_the_expanded_cookbooks

#
# File lib/rbt/information/create_program_version_url_file.rb, line 66
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|
      use_this_for_url1 = :url1
      if File.exist? yaml_file
        dataset = YAML.load_file(yaml_file)
      else
        e 'No file exists at '+sfile(yaml_file)+'.'
      end
      program_name    = File.basename(
        yaml_file.delete_suffix('.yml')
      ).downcase.to_sym
      program_version = dataset[:program_version]
      if program_version.nil?
        # ================================================================= #
        # This safeguard was added in April 2021 because we had a file
        # called ModemManager.yml still.
        # ================================================================= #
        opne 'A '+steelblue('nil')+' entry for program_version.'
        opne tomato('Debug this please.')
        opne 'The yaml file was: '+sfile(yaml_file.to_s)
        exit
      end
      program_url     = dataset[use_this_for_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
    }
    sort_the_array
    # ===================================================================== #
    # Now that we have populated @array_to_be_stored, we must
    # use it to create a .md file.
    # ===================================================================== #
    what = ''.dup
    @array_to_be_stored.each {|entry|
      # =================================================================== #
      # entry may look like this:
      #
      #   ["modemmanager", "1.16.2",
      #    "https://www.freedesktop.org/software/ModemManager/ModemManager-1.16.2.tar.xz",
      #    "09 Apr 2021"]
      #
      # =================================================================== #
      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.file_programs_version_url
    opne "Now #{steelblue('storing')} into the file"
    opne "`#{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/information/create_program_version_url_file.rb, line 42
def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @directory_expanded_cookbooks
  # ======================================================================= #
  @directory_expanded_cookbooks = RBT.directory_expanded_cookbooks?
  # ======================================================================= #
  # === @all_expanded_cookbooks
  # ======================================================================= #
  @all_expanded_cookbooks = []
  # ======================================================================= #
  # === @show_last_update
  # ======================================================================= #
  @show_last_update = false
  # ======================================================================= #
  # === @array_to_be_stored
  # ======================================================================= #
  @array_to_be_stored = []
end
run() click to toggle source
#

run

#
# File lib/rbt/information/create_program_version_url_file.rb, line 194
def run
  obtain_the_expanded_cookbooks
end
sort_the_array() click to toggle source
#

sort_the_array

#
# File lib/rbt/information/create_program_version_url_file.rb, line 177
def sort_the_array
  sorted = @array_to_be_stored.sort_by {|entry|
    entry.first
  }
  @array_to_be_stored = sorted
end