class RBT::Cookbooks::ExpandCookbooks

Constants

NAMESPACE
#

NAMESPACE

#

Public Class Methods

new( expand_which_programs = :all_of_them, run_already = true ) click to toggle source
#

initialize

#
# File lib/rbt/utility_scripts/expand_cookbooks.rb, line 36
def initialize(
    expand_which_programs = :all_of_them,
    run_already           = true
  )
  reset
  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/utility_scripts/expand_cookbooks.rb, line 210
def consider_updating_program_version_and_url_file
  if is_on_roebe?
    # ===================================================================== #
    # On my home system I will auto-update that file as well.
    # ===================================================================== #
    RBT.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/utility_scripts/expand_cookbooks.rb, line 126
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/utility_scripts/expand_cookbooks.rb, line 135
def inform_the_user_what_we_will_do_next
  if main_array?.size < 2
    opnn; e 'We will now expand the program named '+
             sfancy(return_default_program_name_as_string)+
            ' towards its individual yaml file.'
  else
    opnn; e '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/utility_scripts/expand_cookbooks.rb, line 85
def main_array?
  @expand_these_programs
end
obtain_available_cookbooks() click to toggle source
#

obtain_available_cookbooks

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

reset

#
Calls superclass method RBT::Base#reset
# File lib/rbt/utility_scripts/expand_cookbooks.rb, line 50
def reset
  super()
  @expand_these_programs = [] # Initialize it properly.
  @namespace = NAMESPACE
  obtain_available_cookbooks
end
return_default_program_name_as_string() click to toggle source
#

return_default_program_name_as_string

#
# File lib/rbt/utility_scripts/expand_cookbooks.rb, line 92
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

#
# File lib/rbt/utility_scripts/expand_cookbooks.rb, line 256
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/utility_scripts/expand_cookbooks.rb, line 149
def sanitize_this_hash(i)
  if i.is_a? Hash # Only work on Hashes.
    # ===================================================================== #
    # Drop some empty keys next:
    # ===================================================================== #
    if i.has_key?('url3') and i['url3'].is_a?(String) and i['url3'].empty?
      i.delete('url3')
    end
    if i.has_key?('url4') and i['url4'].is_a?(String) and i['url4'].empty?
      i.delete('url4')
    end
    if i.has_key?('url5') and i['url5'].is_a?(String) and i['url5'].empty?
      i.delete('url5')
    end
    if i.has_key?('use_this_program_name') and
       i['use_this_program_name'].is_a?(String) and
       i['use_this_program_name'].empty?
      i.delete('use_this_program_name')
    end
    if i.has_key?('use_this_build_directory') and
       i['use_this_build_directory'].is_a?(String) and
       i['use_this_build_directory'].empty?
      i.delete('use_this_build_directory')
    end
    if i.has_key?('recommended_deps_on') and
       i['recommended_deps_on'].is_a?(String) and
       i['recommended_deps_on'].empty?
      i.delete('recommended_deps_on')
    end
    if i.has_key?('rating') and
       i['rating'].is_a?(String) and
       i['rating'].empty?
      i.delete('rating')
    end
    if i.has_key?('sub_dir') and
       i['sub_dir'].is_a?(String) and
       i['sub_dir'].empty?
      i.delete('sub_dir')
    end
    if i.has_key?('svn_url') and
       i['svn_url'].is_a?(String) and
       i['svn_url'].empty?
      i.delete('svn_url')
    end
    if i.has_key?('ruby_premake_commands') and
       i['ruby_premake_commands'].is_a?(String) and
       i['ruby_premake_commands'].empty?
      i.delete('ruby_premake_commands')
    end
    # ===================================================================== #
    # 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/utility_scripts/expand_cookbooks.rb, line 60
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
  # ======================================================================= #
  when /^-?-?help/
    show_help(:then_exit)
  when :all_of_them
    i = @available_programs
  end
  unless i.is_a? Array
    i = [i] # Turn it into an Array.
  end
  @expand_these_programs = i
end
show_help(also_exit = false) click to toggle source
#

show_help

#
# File lib/rbt/utility_scripts/expand_cookbooks.rb, line 101
def show_help(also_exit = false)
  case also_exit
  when :then_exit
    also_exit = true
  end
  opnn; e '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
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/utility_scripts/expand_cookbooks.rb, line 224
def work_on_each_cookbook
  @expand_these_programs.each {|program|
    program = remove_archive_at_the_end(File.basename(program))
    # if program =~ /\d+/
    #   program = ProgramInformation.return_program_name(program)
    # end
    # ^^^ This is not ideal, unfortunately, due to programs such
    # as "help2man".
    _ = RBT::Cookbooks::Cookbook.new(program) { :bypass_menu }
    hash = _.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")
    opnn; e "Now storing the #{royalblue('Hash')} from `#{slateblue(program)}"\
            "` into `#{sfile(into)}`."
    write_what_into(what, into)
  }
end