class RBT::Action::Cookbooks::ExpandCookbooks

Public Class Methods

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

RBT::Action::Cookbooks::ExpandCookbooks[]

#
# File lib/rbt/actions/individual_actions/cookbooks/expand_cookbooks/expand_cookbooks.rb, line 279
def self.[](i = ARGV)
  new(i)
end
new( expand_which_programs = :all_of_them, run_already = true, &block ) click to toggle source
#

initialize

#
# File lib/rbt/actions/individual_actions/cookbooks/expand_cookbooks/expand_cookbooks.rb, line 41
def initialize(
    expand_which_programs = :all_of_them,
    run_already           = true,
    &block
  )
  reset
  case run_already
  # ======================================================================= #
  # === :do_not_run_yet
  # ======================================================================= #
  when :do_not_run_yet
    run_already = false
  end
  set_expand_these_programs(
    expand_which_programs
  )
  run if run_already
end

Public Instance Methods

consider_updating_program_version_and_url_file() click to toggle source
#

consider_updating_program_version_and_url_file

#
# File lib/rbt/actions/individual_actions/cookbooks/expand_cookbooks/expand_cookbooks.rb, line 87
def consider_updating_program_version_and_url_file
  if is_on_roebe?
    # ===================================================================== #
    # On my home system I will auto-update that file as well.
    # ===================================================================== #
    action(:create_program_version_url_file)
  end
end
ensure_that_the_base_directory_exists() click to toggle source
#

ensure_that_the_base_directory_exists

#
# File lib/rbt/actions/individual_actions/cookbooks/expand_cookbooks/expand_cookbooks.rb, line 162
def ensure_that_the_base_directory_exists
  unless File.directory? directory_expanded_cookbooks?
    mkdir(directory_expanded_cookbooks?)
  end
end
inform_the_user_what_we_will_do_next() click to toggle source
#

inform_the_user_what_we_will_do_next

#
# File lib/rbt/actions/individual_actions/cookbooks/expand_cookbooks/expand_cookbooks.rb, line 171
def inform_the_user_what_we_will_do_next
  if main_array?.size < 2
    opne "The program called `"\
          "#{sfancy(return_default_program_name_as_string.downcase)}#{rev}`"\
          " will now be expanded,"
    opne 'towards its individual yaml file.'
  else
    opne "#{rev}We will now expand the whole dataset stored into "\
         "the individual yaml files."
  end
end
main_array?() click to toggle source
#

main_array?

#
# File lib/rbt/actions/individual_actions/cookbooks/expand_cookbooks/expand_cookbooks.rb, line 139
def main_array?
  @expand_these_programs
end
obtain_available_cookbooks() click to toggle source
#

obtain_available_cookbooks

#
# File lib/rbt/actions/individual_actions/cookbooks/expand_cookbooks/expand_cookbooks.rb, line 155
def obtain_available_cookbooks
  @available_programs = available_programs?
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method RBT::Action#reset
# File lib/rbt/actions/individual_actions/cookbooks/expand_cookbooks/expand_cookbooks.rb, line 63
def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @simple_or_complex
  # ======================================================================= #
  @simple_or_complex = :simple
  # ======================================================================= #
  # === @expand_these_programs
  # ======================================================================= #
  @expand_these_programs = [] # Initialize it properly.
  obtain_available_cookbooks
end
return_default_program_name_as_string() click to toggle source
#

return_default_program_name_as_string

#
# File lib/rbt/actions/individual_actions/cookbooks/expand_cookbooks/expand_cookbooks.rb, line 146
def return_default_program_name_as_string
  remove_file_archive_at_the_end(
    File.basename(main_array?.first.to_s)
  )
end
run() click to toggle source
#

run (run tag)

#
# File lib/rbt/actions/individual_actions/cookbooks/expand_cookbooks/expand_cookbooks.rb, line 269
def run
  ensure_that_the_base_directory_exists
  inform_the_user_what_we_will_do_next
  work_on_each_cookbook
  consider_updating_program_version_and_url_file
end
sanitize_this_hash(i) click to toggle source
#

sanitize_this_hash (sanitize tag)

#
# File lib/rbt/actions/individual_actions/cookbooks/expand_cookbooks/expand_cookbooks.rb, line 234
def sanitize_this_hash(i)
  if i.is_a? Hash # Only work on Hashes.
    # ===================================================================== #
    # Next, sort this Hash alphabetically:
    # ===================================================================== #
    array = i.sort_by {|key, value| key }
    i = array.to_h
  end
  i
end
set_expand_these_programs( i = :all_of_them ) click to toggle source
#

set_expand_these_programs

#
# File lib/rbt/actions/individual_actions/cookbooks/expand_cookbooks/expand_cookbooks.rb, line 99
def set_expand_these_programs(
    i = :all_of_them
  )
  if i.is_a? Array
    i = i.first
  end
  i = :all_of_them if i.nil? # Assign to the default value, in this case.
  case i
  # ======================================================================= #
  # === expand_cookbooks --help
  #
  # We must be careful here - some programs such as "help2man" exist,
  # so we can not merely scan for the "help" substring.
  # ======================================================================= #
  when /^-?-?help$/i
    show_help(:then_exit)
  # ======================================================================= #
  # === :all_of_them
  # ======================================================================= #
  when :all_of_them,
       '' # Empty Strings are treated the same since as of May 2022.
    i = @available_programs
  end
  unless i.is_a? Array
    i = [i] # Turn it into an Array.
  end
  i.map! {|entry|
    entry = entry.dup if entry.frozen?
    entry.delete!('-') if entry.include?('-')
    if entry and entry.end_with?('.yml')
      entry.delete_suffix!('.yml')
    end
    entry
  }
  @expand_these_programs = i
end
show_help(also_exit = false) click to toggle source
#

show_help (help tag)

#
# File lib/rbt/actions/individual_actions/cookbooks/expand_cookbooks/expand_cookbooks.rb, line 248
def show_help(also_exit = false)
  case also_exit
  # ======================================================================= #
  # === :then_exit
  # ======================================================================= #
  when :then_exit
    also_exit = true
  end
  opne 'This class will expand the given arguments '\
       '(program names)  into .yml files.'
  e
  e 'Invocation example:'
  e
  e sfancy('  expand_cookbooks rubyprogressbar')
  e
  exit if also_exit
end
simple_or_complex?() click to toggle source
#

simple_or_complex?

#
# File lib/rbt/actions/individual_actions/cookbooks/expand_cookbooks/expand_cookbooks.rb, line 80
def simple_or_complex?
  @simple_or_complex
end
work_on_each_cookbook() click to toggle source
#

work_on_each_cookbook

Work on each cookbook and save the dataset as a hash.

#
# File lib/rbt/actions/individual_actions/cookbooks/expand_cookbooks/expand_cookbooks.rb, line 188
def work_on_each_cookbook
  is_on_roebe = is_on_roebe?
  if @expand_these_programs.size > 1
    opne "#{rev}Various programs will be expanded now, using the "\
         "#{steelblue(simple_or_complex?)}"\
         "#{rev} mode."
  end
  @expand_these_programs.each {|program|
    program = remove_archive_at_the_end(File.basename(program)).downcase
    # if program =~ /\d+/
    #   program = ProgramInformation.return_program_name(program)
    # end
    # ^^^ This is not ideal, unfortunately, due to programs such
    #     as "help2man".
    _ = action(:SanitizeCookbook, program, autogenerate_expanded_dataset: false) { @simple_or_complex }
    hash = _.internal_dataset? # Obtain the full dataset here - our main Hash.
    # ===================================================================== #
    # We will sanitize this Hash a little bit - in particular we will
    # remove empty URL entries, such as "url4: ''", as this does not
    # appear to be too terribly useful. For more sanitize-operation
    # see the method that does the job.
    # ===================================================================== #
    hash = sanitize_this_hash(hash)
    dataset_to_save = YAML.dump(hash)
    what = dataset_to_save
    
    # ===================================================================== #
    # Get the target, aka where to store, next:
    # ===================================================================== #
    into = rds("#{directory_expanded_cookbooks?}#{program}.yml")
    RBT.store_this_expanded_dataset_into_that_yaml_file(what, into)
    opne "Now storing the #{royalblue('Hash')} #{rev}from "\
         "`#{slateblue(program)}#{rev}"\
         "` into `#{sfile(into)}#{rev}`."
    if is_on_roebe
      into = "#{RUBY_SRC_DIR_RBT_YAML}expanded_cookbooks/#{File.basename(into)}"
      opne "Also storing the #{royalblue('Hash')} #{rev}from "\
           "`#{slateblue(program)}"\
           "#{rev}` into `#{sfile(into)}#{rev}`."
    end
  }
end