class RBT::Cookbooks::CheckForInvalidEntriesInThisCookbook

Public Class Methods

new( check_these_entries = ARGV, run_already = true ) { || ... } click to toggle source
#

initialize

#
# File lib/rbt/checks_and_validations/check_for_invalid_entries_in_this_cookbook.rb, line 34
def initialize(
    check_these_entries = ARGV,
    run_already         = true
  )
  reset
  set_check_these_entries(
    check_these_entries
  )
  # ======================================================================= #
  # === Handle blocks next
  # ======================================================================= #
  if block_given?
    yielded = yield
    case yielded
    when :do_not_run_yet
      run_already = false
    end
  end
  case run_already
  # ======================================================================= #
  # === :do_not_run_yet
  # ======================================================================= #
  when :do_not_run_yet
    run_already = false
  end
  run if run_already
end

Public Instance Methods

all_fine() click to toggle source
#

all_fine

#
# File lib/rbt/checks_and_validations/check_for_invalid_entries_in_this_cookbook.rb, line 188
def all_fine
  mediumslateblue('      All fine. ')
end
array_registered_and_valid_cookbook_entries?( i = file_specification_of_registered_cookbook_entries ) click to toggle source
#

array_registered_and_valid_cookbook_entries?

#
# File lib/rbt/checks_and_validations/check_for_invalid_entries_in_this_cookbook.rb, line 250
def array_registered_and_valid_cookbook_entries?(
    i = file_specification_of_registered_cookbook_entries
  )
  YAML.load_file(i)
end
batch_process_the_entries() click to toggle source
#

batch_process_the_entries

#
# File lib/rbt/checks_and_validations/check_for_invalid_entries_in_this_cookbook.rb, line 131
def batch_process_the_entries
  @check_these_entries.each {|this_cookbook_entry|
    if this_cookbook_entry.frozen?
      this_cookbook_entry = this_cookbook_entry.dup
    end
    unless this_cookbook_entry.end_with? '.yml'
      this_cookbook_entry << '.yml'
    end
    unless File.exist? this_cookbook_entry
      this_cookbook_entry = cookbooks_dir?+this_cookbook_entry
    end
    # ===================================================================== #
    # Read in the full dataset next.
    # ===================================================================== #
    @work_on_this_file = this_cookbook_entry
    @dataset = File.readlines(this_cookbook_entry).reject {|line|
      line.start_with? '#'
    }.join(N)
    @first_line = @dataset.split(N).first.strip.delete(':')
    if @first_line.include? ' #'
      @first_line = @first_line.split(' #').first.strip
    end
    # ===================================================================== #
    # We have to check for registered entries.
    # ===================================================================== #
    e "#{rev}Working on the file #{sfile(this_cookbook_entry)} next."
    e
    e return_the_main_counter_then_increment_it+
      ' Checking whether '+
      steelblue('the first entry is the name of the file')+':'
    result = check_if_the_first_entry_is_the_name_of_the_file(this_cookbook_entry)
    consider_to_exit_now(result)
    e all_fine+steelblue(cheering_person)
    e return_the_main_counter_then_increment_it+
      ' Checking whether the yaml file has two url1 entries:'
    result = check_whether_this_yaml_file_has_two_url1_entries(@dataset, this_cookbook_entry)
    consider_to_exit_now(result)
    e "      #{mediumslateblue('All fine here. There are no two url1 entries in that file.')} "\
      "#{steelblue(cheering_person)}"
    e return_the_main_counter_then_increment_it+
      ' Checking whether all left entries are valid:'
    result = check_whether_all_left_entries_are_valid
    consider_to_exit_now(result)
    e all_fine+steelblue(cheering_person)
    e return_the_main_counter_then_increment_it+
      ' Checking whether there is more than one '\
      'program_name_and_program_version entry:'
    result = check_whether_there_is_more_than_one_program_name_and_program_version_entry
    consider_to_exit_now(result)
    e all_fine+steelblue(cheering_person)
    e
  }
end
check_if_the_first_entry_is_the_name_of_the_file(i) click to toggle source
#

check_if_the_first_entry_is_the_name_of_the_file

#
# File lib/rbt/checks_and_validations/check_for_invalid_entries_in_this_cookbook.rb, line 259
def check_if_the_first_entry_is_the_name_of_the_file(i)
  i = File.basename(i)
  name_of_the_file_without_extension = i.sub(/#{File.extname(i)}$/,'')
  if @first_line == name_of_the_file_without_extension
  else
    opnn { :no_colon}
    e
    e crimson('The name of the file is not the same as the filename.')
    e crimson('This should be corrected.')
    e
    e slateblue(@first_line)+
      lightgreen(' != ')+
      royalblue(name_of_the_file_without_extension)
    e
    return :error
  end
end
check_whether_all_left_entries_are_valid() click to toggle source
#

check_whether_all_left_entries_are_valid

This method will check whether the left entries of the file are all valid.

#
# File lib/rbt/checks_and_validations/check_for_invalid_entries_in_this_cookbook.rb, line 214
def check_whether_all_left_entries_are_valid
  # ======================================================================= #
  # Get a handle towards all valid cookbook-entries next. This will
  # include Strings such as "tags" or "url1" and so forth.
  # ======================================================================= #
  valid_entries = array_registered_and_valid_cookbook_entries?
  splitted = @dataset.split(N)
  these_entries_were_found = splitted.select {|entry|
    entry.start_with?(' ') and
   !entry.start_with?(' #') and
   !entry.start_with?(' - ') and
   !entry.start_with?('  ')
  }.map {|line|
    line.strip!
    if line.include? ':'
      line = line.split(':').first
    end
    line.strip!
    line
  }
  # ======================================================================= #
  # Next, check each of these entries:
  # ======================================================================= #
  these_entries_were_found.each {|check_this_entry|
    if valid_entries.include? check_this_entry
    else
      opne crimson('Not registered entry called `')+
           sfancy(check_this_entry)+
           crimson('`.')
    end
  }
end
check_whether_there_is_more_than_one_program_name_and_program_version_entry( i = @dataset ) click to toggle source
#

check_whether_there_is_more_than_one_program_name_and_program_version_entry

#
# File lib/rbt/checks_and_validations/check_for_invalid_entries_in_this_cookbook.rb, line 318
def check_whether_there_is_more_than_one_program_name_and_program_version_entry(
    i = @dataset
  )
  this_file = @work_on_this_file
  # ======================================================================= #
  # We can simply scan() here. The faulty entry may look like this:
  #
  #   program_name_and_program_version: mafft-7.467
  #   program_name_and_program_version: mafft-7.310
  #
  # ======================================================================= #
  scanned = i.scan(/ program_name_and_program_version: /)
  if scanned.size > 1
    opne swarn('There are too many')+
         steelblue(' program_name_and_program_version: ')+
         swarn('entries in that file.')
    opne swarn('Please fix this issue, in the following file:')
    e
    e sfile("  #{this_file}")
    e
    return :error
  end
end
check_whether_this_yaml_file_has_two_url1_entries( i = @dataset, this_file = nil ) click to toggle source
#

check_whether_this_yaml_file_has_two_url1_entries

This method will return a boolean value - true if the .yml file has two url1 entries, and false otherwise.

#
# File lib/rbt/checks_and_validations/check_for_invalid_entries_in_this_cookbook.rb, line 283
def check_whether_this_yaml_file_has_two_url1_entries(
    i = @dataset, this_file = nil
  )
  this_file = this_file.first if this_file.is_a? Array
  if this_file
    unless this_file.include? '/'
      this_file = File.absolute_path(this_file)
    end
  end
  case i
  # ======================================================================= #
  # === :default
  # ======================================================================= #
  when :default,
       nil
    if File.exist? this_file
      i = @dataset = File.read(this_file)
    end
  end
  n_url1_entries = i.scan(/^ url1: /).size
  if n_url1_entries > 1
    opne swarn('There are too many')+steelblue(' url1: ')+
         swarn('entries in that file.')
    opne swarn('Please fix this issue, in the following file:')
    e
    e sfile("  #{this_file}")
    e
    return :error
  end
  return false
end
consider_to_exit_now(i) click to toggle source
#

consider_to_exit_now

#
# File lib/rbt/checks_and_validations/check_for_invalid_entries_in_this_cookbook.rb, line 121
def consider_to_exit_now(i)
  if i == :error
    opne 'Please fix this error before we can continue.'
    exit
  end
end
main_counter?() click to toggle source
#

main_counter?

#
# File lib/rbt/checks_and_validations/check_for_invalid_entries_in_this_cookbook.rb, line 195
def main_counter?
  @internal_hash[:main_counter]
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method RBT::Base#reset
# File lib/rbt/checks_and_validations/check_for_invalid_entries_in_this_cookbook.rb, line 65
def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @dataset
  #
  # This variable must be nil initially.
  # ======================================================================= #
  @dataset = nil
  # ======================================================================= #
  # === @work_on_this_file
  #
  # This variable keeps track on which file we are currently working on.
  # ======================================================================= #
  @work_on_this_file = nil
  # ======================================================================= #
  # === :main_counter
  # ======================================================================= #
  @internal_hash[:main_counter] = 1
end
return_the_main_counter_then_increment_it() click to toggle source
#

return_the_main_counter_then_increment_it

#
# File lib/rbt/checks_and_validations/check_for_invalid_entries_in_this_cookbook.rb, line 202
def return_the_main_counter_then_increment_it
  result = "  (#{royalblue(main_counter?)})"
  @internal_hash[:main_counter] += 1
  return result
end
run() click to toggle source
#

run (run tag)

#
# File lib/rbt/checks_and_validations/check_for_invalid_entries_in_this_cookbook.rb, line 345
def run
  batch_process_the_entries
end
sanitize_the_main_entries() click to toggle source
#

sanitize_the_main_entries

#
# File lib/rbt/checks_and_validations/check_for_invalid_entries_in_this_cookbook.rb, line 97
def sanitize_the_main_entries
  case @check_these_entries.first # case tag
  # ======================================================================= #
  # === --everything
  # ======================================================================= #
  when /^-?-?everything$/i
    @check_these_entries = available_programs?.map {|line| "#{line}.yml" }
  end
  # ======================================================================= #
  # Work through the .yml files next:
  # ======================================================================= #
  @check_these_entries.map! {|entry|
    if entry.end_with? '.yml'
      unless File.exist? entry
        entry = return_location_to_this_programs_yaml_file(entry)
      end
    end
    entry
  }
end
set_check_these_entries(i) click to toggle source
#

set_check_these_entries

#
# File lib/rbt/checks_and_validations/check_for_invalid_entries_in_this_cookbook.rb, line 89
def set_check_these_entries(i)
  @check_these_entries = [i].flatten.compact
  sanitize_the_main_entries
end