class RBT::Cookbooks::ReportUselessDescriptions

Constants

ALSO_OPEN_VIA_EDITOR
#

ALSO_OPEN_VIA_EDITOR

If this variable is set to true then the problematic programs, that is programs that do not have a useful description, will be opened via the editor. This is mostly useful on my home system, since I can sanitize such problematic programs before publishing the whole gem.

#
DEFAULT_DESCRIPTION_OF_THE_PROGRAM
#

DEFAULT_DESCRIPTION_OF_THE_PROGRAM

This is the generic description that was used in the past for the RBT project. If a .yml file still contains this String then we know that it is essentially an empty description, which should be improved on.

#
SLEEP_FOR_THIS_AMOUNT
#

SLEEP_FOR_THIS_AMOUNT

This sleep delay is only useful if we open the .yml file via an editor.

#

Public Class Methods

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

RBT::Cookbooks::ReportUselessDescriptions[]

#
# File lib/rbt/checks_and_validations/report_useless_descriptions.rb, line 215
def self.[](i = '')
  new(i)
end
new( i = ARGV, run_already = true ) click to toggle source
#

initialize

#
# File lib/rbt/checks_and_validations/report_useless_descriptions.rb, line 75
def initialize(
    i           = ARGV,
    run_already = true
  )
  reset
  set_commandline_arguments(i)
  menu
  run if run_already
end

Public Instance Methods

do_not_open_files_in_the_editor() click to toggle source
#

do_not_open_files_in_the_editor

#
# File lib/rbt/checks_and_validations/report_useless_descriptions.rb, line 133
def do_not_open_files_in_the_editor
  @also_open_via_editor = false
end
iterate_over_every_available_program()
menu( i = commandline_arguments? ) click to toggle source
#

menu (menu tag)

#
report()
Alias for: report_results
report_results() click to toggle source
#

report_results (report tag)

#
# File lib/rbt/checks_and_validations/report_useless_descriptions.rb, line 179
def report_results
  _ = @array_these_programs_are_problematic
  opne "A total of #{sfancy(_.size.to_s)} problematic "\
       "descriptions were found."
  if _.empty?
    opne "This is #{lightgreen('excellent')}! All programs "\
         "appear to have a useful description."
  else
    e
    _.each {|this_program|
      e "  - #{simp(this_program)}"
      if @also_open_via_editor
        target = File.basename(this_program.dup)
        target << '.yml' unless target.end_with? '.yml'
        unless target.start_with? RUBY_SRC_RBT_COOKBOOKS
          target.prepend(RUBY_SRC_RBT_COOKBOOKS)
        end 
        open_in_editor(target)
        sleep SLEEP_FOR_THIS_AMOUNT
      end
    }
    e
  end
end
Also aliased as: report
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method RBT::Base#reset
# File lib/rbt/checks_and_validations/report_useless_descriptions.rb, line 88
def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @raw_cookbook
  # ======================================================================= #
  @raw_cookbook = RBT::Cookbooks::RawCookbook.new { :fast }
  # ======================================================================= #
  # === @array_these_programs_are_problematic
  #
  # Store the problematic programs in the following Array:
  # ======================================================================= #
  @array_these_programs_are_problematic = []
  # ======================================================================= #
  # === @also_open_via_editor
  # ======================================================================= #
  @also_open_via_editor = ALSO_OPEN_VIA_EDITOR
  # ======================================================================= #
  # === @use_this_as_the_key_for_the_description
  # ======================================================================= #
  @use_this_as_the_key_for_the_description = :description
end
run() click to toggle source
#

run (run tag)

#
# File lib/rbt/checks_and_validations/report_useless_descriptions.rb, line 207
def run
  run_through_every_available_program
  report_results
end
run_through_every_available_program() click to toggle source
#

run_through_every_available_program

#
# File lib/rbt/checks_and_validations/report_useless_descriptions.rb, line 147
def run_through_every_available_program
  available_programs?.each {|this_program|
    @raw_cookbook.clear

    hash = @raw_cookbook.load_this_program(this_program)

    if hash.has_key? @use_this_as_the_key_for_the_description
      description = hash[@use_this_as_the_key_for_the_description]
    end
    if hash.nil? or hash.empty?
      this_program_is_problematic(this_program)
    else
      # =================================================================== #
      # Nil descriptions or empty descriptions will be reported.
      # =================================================================== #
      if description.nil? or description.strip.empty?
        this_program_is_problematic(this_program)
      # =================================================================== #
      # As will those programs that conform to a default, but
      # pretty useless, description.
      # =================================================================== #
      elsif description.strip == DEFAULT_DESCRIPTION_OF_THE_PROGRAM
        this_program_is_problematic(this_program)
      # else # Else all seems fine.
      end
    end
  }
end
this_program_is_problematic(this_program) click to toggle source
#

this_program_is_problematic

#
# File lib/rbt/checks_and_validations/report_useless_descriptions.rb, line 140
def this_program_is_problematic(this_program)
  @array_these_programs_are_problematic << this_program
end