class RBT::Cookbooks::ExpandCookbooks
Public Class Methods
new( expand_which_programs = :all_of_them, run_already = true )
click to toggle source
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 166 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
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 138 def inform_the_user_what_we_will_do_next if main_array?.size < 2 opne "We will now expand the program called `"\ "#{sfancy(return_default_program_name_as_string)}`" opne 'towards its individual yaml file.' else opne 'We will now expand the whole dataset stored into '\ 'the individual yaml files.' end end
main_array?()
click to toggle source
obtain_available_cookbooks()
click to toggle source
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() 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
run()
click to toggle source
sanitize_this_hash(i)
click to toggle source
#¶ ↑
sanitize_this_hash
(sanitize tag)¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/expand_cookbooks.rb, line 152 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/utility_scripts/expand_cookbooks.rb, line 67 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| if entry and entry.end_with?('.yml') entry = entry.dup if entry.frozen? 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/utility_scripts/expand_cookbooks.rb, line 178 def show_help(also_exit = false) case also_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
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 198 def work_on_each_cookbook is_on_roebe = is_on_roebe? if @expand_these_programs.size > 1 opne 'Various programs will be expanded now, using the '+ steelblue(@simple_or_complex.to_s)+ ' 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". _ = RBT::Cookbooks::SanitizeCookbook.new(program) { @simple_or_complex } hash = _.internal_dataset? # Obtain the full dataset - 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") opne "Now storing the #{royalblue('Hash')} from "\ "`#{slateblue(program)}"\ "` into `#{sfile(into)}`." write_what_into(what, into) # ===================================================================== # # Since as of May 2020, on roebe systems, we will also store this. # ===================================================================== # if is_on_roebe into = "#{RUBY_SRC_DIR_RBT_YAML}expanded_cookbooks/#{File.basename(into)}" opne "Also storing the #{royalblue('Hash')} from "\ "`#{slateblue(program)}"\ "` into `#{sfile(into)}`." write_what_into(what, into) end } end