class RBT::Cookbooks::CheckForInvalidEntriesInThisCookbook

Constants

NAMESPACE
#

NAMESPACE

#

Public Class Methods

new( check_these_entries = ARGV, run_already = true ) click to toggle source
#

initialize

#
# File lib/rbt/validation/check_for_invalid_entries_in_this_cookbook.rb, line 31
def initialize(
    check_these_entries = ARGV,
    run_already         = true
  )
  reset
  set_check_these_entries(
    check_these_entries
  )
  case run_already
  when :do_not_run_yet
    run_already = false
  end
  run if run_already
end

Public Instance Methods

array_registered_and_valid_cookbook_entries?() click to toggle source
#

array_registered_and_valid_cookbook_entries?

#
# File lib/rbt/validation/check_for_invalid_entries_in_this_cookbook.rb, line 133
def array_registered_and_valid_cookbook_entries?
  YAML.load_file(
    file_specification_of_registered_cookbook_entries
  ).keys
end
batch_process_the_entries() click to toggle source
#

batch_process_the_entries

#
# File lib/rbt/validation/check_for_invalid_entries_in_this_cookbook.rb, line 83
def batch_process_the_entries
  @check_these_entries.each {|this_cookbook_entry|
    @dataset = File.read(this_cookbook_entry)
    @first_line = @dataset.split(N).first.strip.delete(':')
    # ===================================================================== #
    # We have to check for registered entries.
    # ===================================================================== #
    check_if_the_first_entry_is_the_name_of_the_file(this_cookbook_entry)
    check_whether_all_left_entries_are_valid
  }
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/validation/check_for_invalid_entries_in_this_cookbook.rb, line 142
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
  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/validation/check_for_invalid_entries_in_this_cookbook.rb, line 101
def check_whether_all_left_entries_are_valid
  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
      opnn; e crimson('Not registered entry called ')+
              sfancy(check_this_entry)+
              crimson('.')
    end
  }
end
reset() click to toggle source
#

reset

#
Calls superclass method RBT::Base#reset
# File lib/rbt/validation/check_for_invalid_entries_in_this_cookbook.rb, line 49
def reset
  super()
  @namespace = NAMESPACE
end
run() click to toggle source
#

run (run tag)

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

sanitize_the_main_entries

#
# File lib/rbt/validation/check_for_invalid_entries_in_this_cookbook.rb, line 65
def sanitize_the_main_entries
  case @check_these_entries.first # case tag
  when /^-?-?everything$/i
    @check_these_entries = available_programs?.map {|line| "#{line}.yml" }
  end
  @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/validation/check_for_invalid_entries_in_this_cookbook.rb, line 57
def set_check_these_entries(i)
  @check_these_entries = [i].flatten.compact
  sanitize_the_main_entries
end