class RBT::Cookbooks::ScanForMissingLastUpdateEntries

Constants

NAMESPACE
#

NAMESPACE

#
SHALL_WE_EXIT_WHEN_ENCOUNTERING_PROBLEMS
#

SHALL_WE_EXIT_WHEN_ENCOUNTERING_PROBLEMS

#

Public Class Methods

new( i = nil, run_already = true ) click to toggle source
#

initialize

#
# File lib/rbt/validation/scan_for_missing_last_update_entries.rb, line 36
def initialize(
    i           = nil,
    run_already = true
  )
  register_sigint
  reset
  set_input(
    i
  )
  run if run_already
end

Public Instance Methods

backup_this_file(i) click to toggle source
#

backup_this_file

This will store into /Depot/Temp/BackupForCookbooks/

#
# File lib/rbt/validation/scan_for_missing_last_update_entries.rb, line 162
def backup_this_file(i)
  from_here = individual_cookbooks_directory?+File.basename(i)
  _ = rbt_log_dir?+'BackupForCookbooks/'
  mkdir(_) unless Dir.exist? _
  to_there = _+File.basename(i)
  opnn; e 'We will backup the file '+sfile(i)+' to `'+sfile(to_there)+'`.'
  copy_file(from_here, to_there)
end
check_against_menu( i = @input )
Alias for: menu
do_scan() click to toggle source
#

do_scan

#
# File lib/rbt/validation/scan_for_missing_last_update_entries.rb, line 174
def do_scan
  all_programs?.each {|program|
    program.downcase!
    _ = return_location_to_this_programs_yaml_file(program)
    if File.exist? _ # Ok, the file exists.
      begin
        dataset = YAML.load_file(_)
      rescue ArgumentError => error
        e 'An ArgumentError happened for the program `'+
          sfancy(program.to_s)+'`.'
        pp error
      end
      program = program.to_s
      # =================================================================== #
      # Check whether the variable program still ends with '.yml'.
      # If so we chop this part away.
      # =================================================================== #
      if program.end_with? '.yml'
        program.sub!(/\.yml$/,'')
      end
      last_update = dataset[program] # ['last_update:']
      if last_update
        if last_update.has_key? 'last_update'
        else
          if @input.nil?
            opnn; e "A problem with #{sfancy(program.to_s)}."
            opnn; e 'Showcasing the data-structure:'
            pp last_update
            pp last_update.class
          end
          if @input
            opnn unless @input.include? 'besilent'
          end
          _ = File.basename(_)
          @array_with_the_results << _
          display_this_string = sfancy(_)
          if @input
            unless @input.include? 'besilent'
              display_this_string << ' has no last_update entry.'
            end
          end
          e display_this_string
          if fix_missing_entries?
            fix_this_missing_entry(_) # Fix this wrongful information.
          end
        end
      else
        opnn; e 'Something went wrong for `'+simp(program.to_s)+'`.'
        opnn; e 'We could not find an entry called '+sfancy('last_update:')
        opnn; e 'We will display the faulty dataset next.'
        cliner { pp dataset }
        if SHALL_WE_EXIT_WHEN_ENCOUNTERING_PROBLEMS
          opnn; e 'Exiting now, as requested by the constant'
          opnn; efancy 'SHALL_WE_EXIT_WHEN_ENCOUNTERING_PROBLEMS.'
          exit
        end
      end
    else
      opnn; e "The file at #{sfile(_)} does not exist. Exiting now."
      exit
    end
  }
end
fix_missing_entries?() click to toggle source
#

fix_missing_entries?

#
# File lib/rbt/validation/scan_for_missing_last_update_entries.rb, line 132
def fix_missing_entries?
  @fix_missing_entries
end
fix_this_missing_entry(i) click to toggle source
#

fix_this_missing_entry

Use this method to fix a wrongful entry among the individual cookbook entries.

#
# File lib/rbt/validation/scan_for_missing_last_update_entries.rb, line 118
def fix_this_missing_entry(i)
  i = individual_cookbooks_directory?+File.basename(i)
  what = N+' last_update: '+return_proper_time
  opnn; e 'We will next append `'+simp(what.delete(N))+'` into '\
          'the file at: `'+sfile(temp_directory?+File.basename(i))+'`.'
  backup_this_file(i)
  copy_file(i, temp_directory?)
  into = temp_directory?+File.basename(i)
  append_what_into(what, into)
end
menu( i = @input ) click to toggle source
#

menu

#
Also aliased as: check_against_menu
report_how_many_programs_are_missing_the_last_update_entry() click to toggle source
#

report_how_many_programs_are_missing_the_last_update_entry

#
# File lib/rbt/validation/scan_for_missing_last_update_entries.rb, line 80
def report_how_many_programs_are_missing_the_last_update_entry
  opnn; e "We have a total of #{sfancy(results?.size.to_s)}"\
          " programs without a #{swarn('last_update: entry')}."
  if results?.size.to_i == 0
    opnn; e 'Excellent! That means that all cookbook files are valid,'
    opnn; e "in regards to the #{sfancy('last_update tag')}. "+
            gold(return_cheering_person)
    e
    opnn; e 'The directory that we did check for this was:'
    e
    e "  #{sdir(individual_cookbooks_directory?)}"
    e 
  end
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method RBT::Base#reset
# File lib/rbt/validation/scan_for_missing_last_update_entries.rb, line 51
def reset
  super()
  @namespace = NAMESPACE
  @array_with_the_results = []
  @fix_missing_entries = false # By default we will not auto-fix flawed entries.
end
results?() click to toggle source
#

results?

#
# File lib/rbt/validation/scan_for_missing_last_update_entries.rb, line 98
def results?
  @array_with_the_results
end
return_proper_time() click to toggle source
#

return_proper_time

This will return a string such as:

"Apr 2014"
#
# File lib/rbt/validation/scan_for_missing_last_update_entries.rb, line 108
def return_proper_time
  Date::MONTHNAMES[Date.today.month]+Time.now.strftime(' %Y')
end
run() click to toggle source
#

run (run tag)

#
# File lib/rbt/validation/scan_for_missing_last_update_entries.rb, line 254
def run
  check_against_menu
  do_scan # Do the scan part now.
  report_how_many_programs_are_missing_the_last_update_entry # We finally report how many "faulty" programs we have discovered.
  try_to_show_problematic_programs
end
set_input(i = '') click to toggle source
#

set_input

#
# File lib/rbt/validation/scan_for_missing_last_update_entries.rb, line 61
def set_input(i = '')
  i = i.first if i.is_a? Array
  if i
    i = i.to_s.dup
    i = i.delete('_')
  end
  @input = i
end
show_help() click to toggle source
#

show_help

#
# File lib/rbt/validation/scan_for_missing_last_update_entries.rb, line 73
def show_help # help tag
  opnn; ecomment ' FIX # Use this to fix wrongful entries'
end
try_to_show_problematic_programs() click to toggle source
#

try_to_show_problematic_programs

#
# File lib/rbt/validation/scan_for_missing_last_update_entries.rb, line 241
def try_to_show_problematic_programs
  _ = results?
  unless _.empty?
    _.each {|this_program|
      opnn; e 'This program has a problematic last_entry: '+
               sfancy(this_program)
    }
  end
end