class RBT::Action::Cookbooks::CheckForInvalidEntriesInThisCookbook
Public Class Methods
[](i = ARGV)
click to toggle source
new( check_these_entries = ARGV, run_already = true ) { || ... }
click to toggle source
#¶ ↑
initialize¶ ↑
#¶ ↑
# File lib/rbt/actions/individual_actions/checks_and_validations/check_for_invalid_entries_in_this_cookbook.rb, line 42 def initialize( check_these_entries = ARGV, run_already = true, &block ) reset set_commandline_arguments( check_these_entries ) 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 run if run_already end
Public Instance Methods
all_fine()
click to toggle source
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/actions/individual_actions/checks_and_validations/check_for_invalid_entries_in_this_cookbook.rb, line 262 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/actions/individual_actions/checks_and_validations/check_for_invalid_entries_in_this_cookbook.rb, line 330 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. # ===================================================================== # @internal_hash[:work_on_this_file] = this_cookbook_entry @internal_hash[:dataset] = readlines_with_proper_encoding(this_cookbook_entry).reject {|line| line.start_with? '#' }.join(N) @internal_hash[:first_line] = @internal_hash[:dataset].split(N).first.strip.delete(':') if @internal_hash[:first_line].include? ' #' @internal_hash[:first_line] = @internal_hash[:first_line].split(' #').first.strip end # ===================================================================== # # We have to check for registered entries. # ===================================================================== # e "#{rev}Working on the file #{sfile(this_cookbook_entry)} #{rev}next." e e return_the_main_counter_then_increment_it+ rev+' 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+ rev+' 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+ rev+' 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}"\ "#{rev} 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/actions/individual_actions/checks_and_validations/check_for_invalid_entries_in_this_cookbook.rb, line 271 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_these_entries?()
click to toggle source
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/actions/individual_actions/checks_and_validations/check_for_invalid_entries_in_this_cookbook.rb, line 226 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/actions/individual_actions/checks_and_validations/check_for_invalid_entries_in_this_cookbook.rb, line 196 def check_whether_there_is_more_than_one_program_name_and_program_version_entry( i = dataset? ) this_file = @internal_hash[: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/actions/individual_actions/checks_and_validations/check_for_invalid_entries_in_this_cookbook.rb, line 146 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 = @internal_hash[:dataset] = read_file_with_default_encoding(this_file) end end begin n_url1_entries = i.scan(/^ url1: /).size rescue ArgumentError => error e "#{rev}Error for: #{sfile(this_file)}" pp error end 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/actions/individual_actions/checks_and_validations/check_for_invalid_entries_in_this_cookbook.rb, line 316 def consider_to_exit_now(i) case i # ======================================================================= # # === :error # ======================================================================= # when :error opne 'Please fix this error before we can continue.' exit end end
dataset?()
click to toggle source
first_line?()
click to toggle source
main_counter?()
click to toggle source
reset()
click to toggle source
#¶ ↑
reset (reset tag)¶ ↑
#¶ ↑
Calls superclass method
RBT::Action#reset
# File lib/rbt/actions/individual_actions/checks_and_validations/check_for_invalid_entries_in_this_cookbook.rb, line 70 def reset super() infer_the_namespace # ======================================================================= # # === :main_counter # ======================================================================= # @internal_hash[:main_counter] = 1 # ======================================================================= # # === :work_on_this_file # # This variable keeps track on which file we are currently working on. # ======================================================================= # @internal_hash[:work_on_this_file] = nil # ======================================================================= # # === :dataset # # This variable must be nil initially. # ======================================================================= # @internal_hash[:dataset] = nil # ======================================================================= # # === :first_line # ======================================================================= # @internal_hash[:first_line] = nil end
return_the_main_counter_then_increment_it()
click to toggle source
#¶ ↑
return_the_main_counter_then_increment_it
¶ ↑
#¶ ↑
# File lib/rbt/actions/individual_actions/checks_and_validations/check_for_invalid_entries_in_this_cookbook.rb, line 134 def return_the_main_counter_then_increment_it result = " #{rev}(#{royalblue(main_counter?)}#{rev})" @internal_hash[:main_counter] += 1 return result end
run()
click to toggle source
sanitize_the_main_entries()
click to toggle source
#¶ ↑
sanitize_the_main_entries
¶ ↑
#¶ ↑
# File lib/rbt/actions/individual_actions/checks_and_validations/check_for_invalid_entries_in_this_cookbook.rb, line 292 def sanitize_the_main_entries case @internal_hash[:check_these_entries].first # case tag # ======================================================================= # # === --everything # ======================================================================= # when /^-?-?everything$/i @internal_hash[:check_these_entries] = available_programs?.map {|line| "#{line}.yml" } end # ======================================================================= # # Work through the .yml files next: # ======================================================================= # @internal_hash[: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