class RBT::Action::ShowAllAbout

Public Class Methods

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

RBT::Action::ShowAllAbout[]

#
# File lib/rbt/actions/individual_actions/information/show_all_about.rb, line 381
def self.[](i = ARGV)
  new(i)
end
new( this_program = nil, run_already = true ) click to toggle source
#

initialize

#
# File lib/rbt/actions/individual_actions/information/show_all_about.rb, line 38
def initialize(
    this_program = nil, # We specifically avoid using ARGV here.
    run_already  = true
  )
  reset
  set_program(
    this_program
  )
  run if run_already
end

Public Instance Methods

colourize_or_dont_colourize_in_steelblue(i) click to toggle source
#

colourize_or_dont_colourize_in_steelblue

#
# File lib/rbt/actions/individual_actions/information/show_all_about.rb, line 140
def colourize_or_dont_colourize_in_steelblue(i)
  if use_colours?
    i = steelblue(i).dup
  end
  return i
end
determine_available_programs() click to toggle source
#

determine_available_programs

#
# File lib/rbt/actions/individual_actions/information/show_all_about.rb, line 133
def determine_available_programs
  @available_programs = available_programs?
end
menu(i) click to toggle source
#

menu (menu tag)

#
program_name?() click to toggle source
#

program_name?

#
# File lib/rbt/actions/individual_actions/information/show_all_about.rb, line 126
def program_name?
  @program
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method RBT::Action#reset
# File lib/rbt/actions/individual_actions/information/show_all_about.rb, line 52
def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @n_header_files_so_far
  # ======================================================================= #
  @n_header_files_so_far  = 0
  # ======================================================================= #
  # === @n_library_files_so_far
  #
  # This variable can also be used to determine how many library
  # files are in this dataset.
  # ======================================================================= #
  @n_library_files_so_far = 0
  # ======================================================================= #
  # === @limit_to_n_headers
  #
  # This variable is set to a low value initially, 10 right now.
  # ======================================================================= #
  @limit_to_n_headers = 10
  # ======================================================================= #
  # === @limit_to_n_libraries
  #
  # This variable is set to a low value initially, 10 right now.
  # ======================================================================= #
  @limit_to_n_libraries = 10
end
return_n_headers() click to toggle source
#

return_n_headers

#
# File lib/rbt/actions/individual_actions/information/show_all_about.rb, line 325
def return_n_headers
  @cookbook_dataset.n_headers?
end
return_n_libraries() click to toggle source
#

return_n_libraries

#
# File lib/rbt/actions/individual_actions/information/show_all_about.rb, line 332
def return_n_libraries
  @cookbook_dataset.n_libraries?
end
run() click to toggle source
#

run (run tag)

#
# File lib/rbt/actions/individual_actions/information/show_all_about.rb, line 339
def run
  _ = program_name?.downcase # Must downcae it since as of Jan 2018.
  determine_available_programs
  if @available_programs.include? _
    opne "Now showing all about `#{seagreen(_)}#{rev}`.#{N}#{N}"
    cookbook_location = "#{individual_cookbooks_directory?}#{_}.yml"
    # ===================================================================== #
    # Check whether the cookbook .yml file exists.
    # ===================================================================== #
    if File.exist? cookbook_location
      # =================================================================== #
      # Since as of January 2018, we will also check this cookbook file
      # for errors.
      # =================================================================== #
      if Object.const_defined?(:RBT) and
         RBT.respond_to?(:does_this_cookbook_file_have_any_erroneous_entry?)
        if RBT.does_this_cookbook_file_have_any_erroneous_entry?(cookbook_location)
          opne "#{rev}Note that the file `#{sfile(cookbook_location)}#{rev}`"
          opne "#{rev}has at the least one erroneous entry."
          RBT.check_this_cookbook_file_for_errors(cookbook_location)
        end
      end
    end
    # ===================================================================== #
    # Simply use File.readlines() rather than YAML.load_file() next.
    # ===================================================================== #
    _ = File.basename(cookbook_location).
        delete_suffix('.yml')
    @cookbook_dataset = ::RBT.load_this_cookbook(_)
    dataset = readlines_with_proper_encoding(cookbook_location)
    dataset = sanitize_this_dataset(dataset)
    dataset = dataset.join
    cliner { e dataset }
  else
    opne "#{rev}No program called `#{seagreen(_)}#{rev}` appears "\
         "to be registered.#{N}"
  end
end
sanitize_this_dataset(i) click to toggle source
#

sanitize_this_dataset

This method will return the dataset, which is an Array.

#
# File lib/rbt/actions/individual_actions/information/show_all_about.rb, line 218
def sanitize_this_dataset(i)
  i.map! {|entry|
    entry = entry.dup if entry.frozen?
    # ===================================================================== #
    # Build up our temporary string next.
    # ===================================================================== #
    result = ''.dup
    # ===================================================================== #
    # Only deal with entries that could start with " - ".
    # ===================================================================== #
    if entry.chomp == ' headers:'
      entry.chomp!
      entry << colourize_or_dont_colourize_in_steelblue(
        "  [#{return_n_headers} headers]#{rev}\n".dup
      )+rev
    elsif entry.chomp == ' libraries:'
      entry.chomp!
      entry = rev+entry
      entry << rev+colourize_or_dont_colourize_in_steelblue(
        "  [#{return_n_libraries} libraries]#{rev}\n".dup
      )+rev
    end
    if entry.start_with?(' - ')
      # =================================================================== #
      # === Handle library files
      #
      # Handle library files (.so files and .a files) next:
      # =================================================================== #
      if is_this_a_library?(entry)
        @n_library_files_so_far += 1
        if @limit_to_n_libraries
          if @n_library_files_so_far < @limit_to_n_libraries
            # Pass through.
          elsif @n_library_files_so_far == @limit_to_n_libraries
            add_this = "   [Truncated ... no more .so / .a files shown "\
                       "past the #{@limit_to_n_libraries} .so / .a files limit.]#{rev}\n".dup
            if use_colours?
              add_this = steelblue(add_this).dup
            end
            next_line = "   [You can use --do-not-truncate to ignore the above limit.]#{rev}\n" 
            if use_colours?
              splitted = next_line.split('--do-not-truncate')
              next_line = steelblue(splitted[0])+
                          tomato('--do-not-truncate')+
                          steelblue(splitted[1])+
                          rev
            end
            add_this << next_line
            entry << add_this
          else
            entry = ''
          end
        end
      # =================================================================== #
      # === Handle header files
      #
      # Handle header files, such as .h in particular, next:
      # =================================================================== #
      elsif is_this_a_header?(entry)
        @n_header_files_so_far += 1
        if @limit_to_n_headers
          if @n_header_files_so_far < @limit_to_n_headers
            # Pass through.
          elsif @n_header_files_so_far == @limit_to_n_headers
            add_this = "   [Truncated ... no more .h files shown "\
                       "past the #{@limit_to_n_headers} .h files limit.]\n".dup
            add_this << "#{rev}   [You can use --do-not-truncate to "\
                        "ignore the above limit.]\n" 
            if use_colours?
              add_this = steelblue(add_this)
            end
            entry << add_this
          else
            entry = ''
          end
        end
      else # else we don't need to modify anything.
      end
    # ===================================================================== #
    # === Check if we have the homepage: entry here
    #
    # If so then we will modify this a bit, in the sense of
    # colourizing the homepage: entry in the colour orange.
    # ===================================================================== #
    elsif entry.start_with? ' homepage: '
      entry = "#{orange(entry)}#{rev}"
    # ===================================================================== #
    # === git_url:
    # ===================================================================== #
    elsif entry.start_with? ' git_url: '
      entry = mediumslateblue(entry)+rev
    end
    # ===================================================================== #
    # Pad it with two ' ' on the left side a bit.
    # ===================================================================== #
    result << "  #{entry}" unless entry.empty?
    # ===================================================================== #
    # Return this result.
    # ===================================================================== #
    result
  }
  i
end
set_program(i) click to toggle source
#

set_program

This method will set the program name.

#
# File lib/rbt/actions/individual_actions/information/show_all_about.rb, line 152
def set_program(i)
  if i.is_a? Array
    menu(
      i[1 .. -1]
    )
    i = i.first
  end
  if i.nil?
    # ===================================================================== #
    # In this case, if the user did not provide anything useful, we will
    # simply try to use a name inferred from the current working directory.
    # ===================================================================== #
    possible_name = ::ProgramInformation.return_program_name(
      File.basename(return_pwd)
    )
    i = possible_name if possible_name
  end
  original_input = i.dup
  # ======================================================================= #
  # The input may include '_', '-' or '.', which are not a valid name
  # for a cookbook-recipe, so we get rid of these characters.
  # ======================================================================= #
  i = i.dup if i.frozen?
  i.delete!('-') if i.include? '-'
  i.delete!('_') if i.include? '_'
  i.delete!('.') if i.include? '.' # <- Trailing '.' are disallowed.
  i = RBT.return_alias_program_name_for(i)
  if original_input != i
    opne "#{rev}Using the alias name `#{sfancy(i)}#{rev}` rather "\
         "than `#{royalblue(original_input)}#{rev}`."
  end
  # ======================================================================= #
  # Make use of Cookbook-aliases next, so that "libatomic" is a valid
  # alias for "libatomic_ops".
  # ======================================================================= #
  unless RBT.does_include?(i)
    # ===================================================================== #
    # Ok the program is not there.
    # ===================================================================== #
    possible_new_name = RBT.return_alias_program_name_for(i)
    unless possible_new_name == i
      i = possible_new_name
    end
    unless RBT.does_include?(i)
      # =================================================================== #
      # Try to prepend 'lib' there and try again.
      # =================================================================== #
      if RBT.does_include?("lib#{i}")
        i = i.dup if i.frozen?
        i.prepend('lib')
        opne 'We found another program name ('+sfancy(i)+rev+
             ') - will use this one instead.'
      elsif i.start_with?('lib') and RBT.does_include?(i[3..-1])
        i = i[3..-1]
      end
    end
  end
  @program = i
  menu(i)
end
show_help() click to toggle source
#

show_help (help tag)

#
# File lib/rbt/actions/individual_actions/information/show_all_about.rb, line 114
def show_help
  unless Object.const_defined? :ClassDocuShower
    require 'class_docu_shower'
  end
  opne 'This is what this class will do:'
  e
  ClassDocuShower[__FILE__]
end