class RBT::Action::CreateProgramVersionUrlFile

Public Class Methods

[](i = ARGV) click to toggle source
#

RBT::Action::CreateProgramVersionUrlFile[]

#
# File lib/rbt/actions/individual_actions/information/create_program_version_url_file.rb, line 229
def self.[](i = ARGV)
  new(i)
end
new( run_already = true ) { || ... } click to toggle source
#

initialize

#
# File lib/rbt/actions/individual_actions/information/create_program_version_url_file.rb, line 31
def initialize(
    run_already = true
  )
  reset
  # ======================================================================= #
  # === Handle blocks next
  # ======================================================================= #
  if block_given?
    yielded = yield
    # ===================================================================== #
    # === Handle Hashes next
    # ===================================================================== #
    if yielded.is_a? Hash and
       yielded.has_key?(:show_last_update)
      @internal_hash[:show_last_update] = yielded.delete(:show_last_update)
    end
  end
  run if run_already
end

Public Instance Methods

all_expanded_cookbooks?() click to toggle source
#

all_expanded_cookbooks?

#
# File lib/rbt/actions/individual_actions/information/create_program_version_url_file.rb, line 78
def all_expanded_cookbooks?
  @internal_hash[:all_expanded_cookbooks]
end
array_to_be_stored?() click to toggle source
#

array_to_be_stored?

#
# File lib/rbt/actions/individual_actions/information/create_program_version_url_file.rb, line 215
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/actions/individual_actions/information/create_program_version_url_file.rb, line 179
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/actions/individual_actions/information/create_program_version_url_file.rb, line 85
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?
    @internal_hash[: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) # Add the program version here.
      # =================================================================== #
      # === Last updated when
      #
      # Append when the last update happened, if we use that entry at
      # all.
      # =================================================================== #
      if show_last_update?
        what << last_update.to_s.strip.ljust(19) # Add when it was last updated.
      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 "#{rev}Now #{steelblue('storing')} #{rev}into the file"
    opne "#{rev}`#{sfile(into)}#{rev}`."
    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 (reset tag)

#
Calls superclass method RBT::Action#reset
# File lib/rbt/actions/individual_actions/information/create_program_version_url_file.rb, line 54
def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @directory_expanded_cookbooks
  # ======================================================================= #
  @directory_expanded_cookbooks = RBT.directory_expanded_cookbooks?
  # ======================================================================= #
  # === :all_expanded_cookbooks
  # ======================================================================= #
  @internal_hash[:all_expanded_cookbooks] = []
  # ======================================================================= #
  # === :show_last_update
  # ======================================================================= #
  @internal_hash[:show_last_update] = false
  # ======================================================================= #
  # === @array_to_be_stored
  # ======================================================================= #
  @array_to_be_stored = []
end
run() click to toggle source
#

run (run tag)

#
# File lib/rbt/actions/individual_actions/information/create_program_version_url_file.rb, line 222
def run
  obtain_the_expanded_cookbooks
end
show_last_update?() click to toggle source
#

show_last_update?

#
# File lib/rbt/actions/individual_actions/information/create_program_version_url_file.rb, line 208
def show_last_update?
  @internal_hash[:show_last_update]
end
sort_the_array() click to toggle source
#

sort_the_array

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