class RBT::Cookbooks::ValidateAllCookbookEntries
Constants
- REGEX_FOR_PREFIX_AND_KEEP_EXTRACTED_IN_CLOSE_PROXIMITY
#¶ ↑
REGEX_FOR_PREFIX_AND_KEEP_EXTRACTED_IN_CLOSE_PROXIMITY
¶ ↑See: rubular.com/r/GHDZk46hyYSrg8
#¶ ↑
- REGEX_TO_USE_FOR_PYTHON_TAGS
#¶ ↑
REGEX_TO_USE_FOR_PYTHON_TAGS
¶ ↑#¶ ↑
- REGEX_TO_USE_FOR_RUBY_TAGS
#¶ ↑
REGEX_TO_USE_FOR_RUBY_TAGS
¶ ↑See: rubular.com/r/OKjmIgdA2g7evu
#¶ ↑
Public Class Methods
[](i = '')
click to toggle source
new( commandline_arguments = nil, run_already = true )
click to toggle source
Public Instance Methods
does_the_keep_extracted_entry_occur_before_the_prefix_entry?( dataset_to_use )
click to toggle source
#¶ ↑
does_the_keep_extracted_entry_occur_before_the_prefix_entry?¶ ↑
The input to this method is assumed to be an Array.
#¶ ↑
# File lib/rbt/checks_and_validations/validate_all_cookbook_entries.rb, line 121 def does_the_keep_extracted_entry_occur_before_the_prefix_entry?( dataset_to_use ) position_of_prefix = dataset_to_use.index { |entry| entry.include? ' prefix:' } position_of_keep_extracted = dataset_to_use.index { |entry| entry.include? ' keep_extracted:' } if position_of_keep_extracted.nil? # e "Missing #{steelblue('keep_extracted')} entry." nil elsif position_of_prefix.nil? # e "Missing #{steelblue('prefix')} entry." nil else position_of_prefix > position_of_keep_extracted # Return this evaluation here. end end
open_n_files?()
click to toggle source
open_this_file_with_default_delay(i)
click to toggle source
#¶ ↑
open_this_file_with_default_delay
(open tag)¶ ↑
#¶ ↑
# File lib/rbt/checks_and_validations/validate_all_cookbook_entries.rb, line 147 def open_this_file_with_default_delay(i) unless open_n_files? == :all_of_them return if @counter >= open_n_files? end @counter += 1 @how_many_individual_problems_have_been_encountered += 1 open_in_editor(i) sleep 1 end
reset()
click to toggle source
#¶ ↑
reset (reset tag)¶ ↑
#¶ ↑
Calls superclass method
RBT::Base#reset
# File lib/rbt/checks_and_validations/validate_all_cookbook_entries.rb, line 73 def reset super() infer_the_namespace # ======================================================================= # # === :open_n_files # ======================================================================= # @internal_hash[:open_n_files] = :all_of_them # ======================================================================= # # === @counter # ======================================================================= # @counter = 0 # ======================================================================= # # === @how_many_individual_problems_have_been_encountered # ======================================================================= # @how_many_individual_problems_have_been_encountered = 0 end
return_coloured_cheering_person()
click to toggle source
run()
click to toggle source
#¶ ↑
run (run tag)¶ ↑
#¶ ↑
# File lib/rbt/checks_and_validations/validate_all_cookbook_entries.rb, line 423 def run work_through_every_cookbook_file if @how_many_individual_problems_have_been_encountered == 0 opne 'No problem has been encountered. '+return_coloured_cheering_person else opne 'There were '+sfancy(@how_many_individual_problems_have_been_encountered)+ ' individual problems discovered.' end end
set_commandline_arguments(i = '')
click to toggle source
work_through_every_cookbook_file()
click to toggle source
#¶ ↑
work_through_every_cookbook_file
(logic tag)¶ ↑
This is the main powerhorse method of this class.
#¶ ↑
# File lib/rbt/checks_and_validations/validate_all_cookbook_entries.rb, line 169 def work_through_every_cookbook_file is_on_roebe = is_on_roebe? sorted_programs = available_programs?.sort sorted_programs.each_with_index {|this_program, index| target_yaml_file = return_yaml_file_for(this_program).dup # ===================================================================== # # ::RBT.check_for_invalid_entries_in_this_cookbook_file(target_yaml_file) # ^^^ Unfortunately the above does not work right now (28.09.2019) # so it has been disabled until the class is fixed. # ===================================================================== # regular_dataset = default_readlines(target_yaml_file) string_representation_of_this_dataset = regular_dataset.join # ===================================================================== # # === tags: " # # This entry point is used to report erroneous tags: entries. For # the purpose of the definition here, a wrong "tags:" entry is one # that has a trailing ' ' after the "tags:" part. We assume here # that the user did not break it down onto the next line, as an # Array. # ===================================================================== # if string_representation_of_this_dataset.include? 'tags: ' e "Wrong tags: entry in the file #{sfile(target_yaml_file)}" open_this_file_with_default_delay(target_yaml_file) if is_on_roebe end # ===================================================================== # # === Report "tags" entry occurring AFTER "required_deps_on" entry # # The proper fix for this is to put the tag entry before the # required_deps_on entry. # ===================================================================== # if string_representation_of_this_dataset.include?(' tags:') and string_representation_of_this_dataset.include?(' required_deps_on:') and ( string_representation_of_this_dataset.index(' required_deps_on:') < string_representation_of_this_dataset.index(' tags:') ) e "The required_deps_on: entry occurs before the "\ "tags: entry, for #{sfile(target_yaml_file)}" open_this_file_with_default_delay(target_yaml_file) if is_on_roebe end # ===================================================================== # # === Report "prefix" entry occurring AFTER the "tags" entry # # The proper fix for this is to put the "prefix" entry before the # "tags" entry. # ===================================================================== # if string_representation_of_this_dataset.include?(' tags:') and string_representation_of_this_dataset.include?(' prefix:') and ( string_representation_of_this_dataset.index(' tags:') < string_representation_of_this_dataset.index(' prefix:') ) e "The tags: entry occurs before the "\ "prefix: entry, for #{sfile(target_yaml_file)}" open_this_file_with_default_delay(target_yaml_file) if is_on_roebe end # ===================================================================== # # === Report "configure_options:" being shown after "description: " # ===================================================================== # if string_representation_of_this_dataset.include?(' description:') and string_representation_of_this_dataset.include?(' configure_options:') and ( string_representation_of_this_dataset.index(' description:') < string_representation_of_this_dataset.index(' configure_options:') ) e "The tags: entry occurs before the "\ "prefix: entry, for #{sfile(target_yaml_file)}" open_this_file_with_default_delay(target_yaml_file) if is_on_roebe end # ===================================================================== # # === Report the situation were "prefix" occurs before "url1" # # The proper fix for this is to put the "prefix" entry after # the "url1" entry. # ===================================================================== # if string_representation_of_this_dataset.include?(' prefix:') and string_representation_of_this_dataset.include?(' url1:') and ( string_representation_of_this_dataset.index(' prefix:') < string_representation_of_this_dataset.index(' url1:') ) e "The tags: prefix occurs before the "\ "url1: entry, for #{sfile(target_yaml_file)}" open_this_file_with_default_delay(target_yaml_file) if is_on_roebe end # ===================================================================== # # === Report 'required_deps_on:' occurring before 'prefix:' # ===================================================================== # if string_representation_of_this_dataset.include?(' required_deps_on:') and string_representation_of_this_dataset.include?(' prefix:') and ( string_representation_of_this_dataset.index(' required_deps_on:') < string_representation_of_this_dataset.index(' prefix:') ) e "The required_deps_on: entry occurs before the "\ "prefix: entry, for #{sfile(target_yaml_file)}" open_this_file_with_default_delay(target_yaml_file) if is_on_roebe end # ===================================================================== # # === Report "short_description" entry occurring before "configure_options" # # The proper fix for this is to put the configure_options entry # before the "short_description" entry. # ===================================================================== # if string_representation_of_this_dataset.include?(' configure_options:') and string_representation_of_this_dataset.include?(' short_description:') and ( string_representation_of_this_dataset.index(' short_description:') < string_representation_of_this_dataset.index(' configure_options:') ) e "The configure_options: entry occurs after the "\ "short_description: entry, for #{sfile(target_yaml_file)}" open_this_file_with_default_delay(target_yaml_file) if is_on_roebe end # ===================================================================== # # === binaries: " # # This entry point is used to report erroneous binaries: entries. # The reasoning goes similar to the "tags: " entry above. # ===================================================================== # if string_representation_of_this_dataset.include? 'binaries: ' e "Wrong binaries: entry in the file #{sfile(target_yaml_file)}" open_this_file_with_default_delay(target_yaml_file) if is_on_roebe end # ===================================================================== # # === More than two "url1:" entries # ===================================================================== # if string_representation_of_this_dataset.scan(/url1: /).size > 1 e "At the least two url1: entries for #{sfile(target_yaml_file)}" open_this_file_with_default_delay(target_yaml_file) if is_on_roebe end # ===================================================================== # # === configure_options: " # # Checking for a single '"' is enough, because some entries may include # two '""', but these are already handled by the first '"' anyway. # ===================================================================== # if string_representation_of_this_dataset.include? 'configure_options: "' e "Wrong configure_options: entry for #{sfile(target_yaml_file)}" open_this_file_with_default_delay(target_yaml_file) if is_on_roebe end # ===================================================================== # # === "Extra information for this program to use." # ===================================================================== # if string_representation_of_this_dataset.include? '"Extra information for this program to use."' e 'Wrong extra_information: in the file '+sfile(target_yaml_file) open_this_file_with_default_delay(target_yaml_file) if is_on_roebe end # ===================================================================== # # === Handle entries with an erroneous description: entry next # ===================================================================== # if string_representation_of_this_dataset.include? ' description: | ""' e 'Wrong description entry for '+sfile(target_yaml_file) open_this_file_with_default_delay(target_yaml_file) if is_on_roebe end # ===================================================================== # # === Handle entries with an erroneous extra_information: entry next # ===================================================================== # if string_representation_of_this_dataset.include? ' extra_information: | ""' e "Wrong extra_information: entry for #{sfile(target_yaml_file)}" open_this_file_with_default_delay(target_yaml_file) if is_on_roebe end # ===================================================================== # # === Handle "required_deps_on: " entries next # ===================================================================== # if string_representation_of_this_dataset.include? 'required_deps_on: ' e "#{rev}Slightly incorrect #{steelblue('required_deps_on: ')}"\ "entry for #{sfile(target_yaml_file)}" open_this_file_with_default_delay(target_yaml_file) if is_on_roebe end # ===================================================================== # # === short_description: " # # Check for entries that have a flawed short_description: " # string. This also includes entries that do NOT have the '|' # token there, so we only check for that one. # ===================================================================== # if (string_representation_of_this_dataset.include?('short_description:') and !string_representation_of_this_dataset.include?('short_description: |')) or string_representation_of_this_dataset.include?('short_description: | ') e 'Wrong '+steelblue('short_description: ')+ 'entry in the file '+sfile(target_yaml_file) open_this_file_with_default_delay(target_yaml_file) if is_on_roebe end # ===================================================================== # # === Report entries where "prefix:" and "keep_extracted:" are not # close together # # prefix: should be followed by keep_extracted: on the next line, # IF both are included. # ===================================================================== # if ( string_representation_of_this_dataset.include?('prefix: ') and string_representation_of_this_dataset.include?('keep_extracted: ') and !(string_representation_of_this_dataset =~ REGEX_FOR_PREFIX_AND_KEEP_EXTRACTED_IN_CLOSE_PROXIMITY) ) e 'Wrong '+steelblue('prefix: ')+' and '+ steelblue('keep_extracted: ')+'combination in '\ 'the file '+sfile(target_yaml_file) e 'These entries should be close together, e. g. first '\ 'prefix:, next line keep_extracted:' open_this_file_with_default_delay(target_yaml_file) if is_on_roebe end # ===================================================================== # # === Report missing " homepage: " entries (homepage tag) # ===================================================================== # unless string_representation_of_this_dataset.include?(' homepage: ') e "There is #{gold('no homepage:')} entry for #{sfile(target_yaml_file)}" open_this_file_with_default_delay(target_yaml_file) if is_on_roebe end # ===================================================================== # # Note that we won't check for "prefix:" if we deal with # ruby files and python files. The following lines of code # achieve precisely that. # ===================================================================== # if (regular_dataset.any? {|line| line =~ /^ - ruby$/ } and (string_representation_of_this_dataset =~ REGEX_TO_USE_FOR_RUBY_TAGS)) or (regular_dataset.any? {|line| line =~ /^ - python$/ } and (string_representation_of_this_dataset =~ REGEX_TO_USE_FOR_PYTHON_TAGS)) # =================================================================== # # In this case we will simply pass through. # =================================================================== # else does_the_keep_extracted_entry_occur_before_the_prefix_entry = does_the_keep_extracted_entry_occur_before_the_prefix_entry?( regular_dataset ) if does_the_keep_extracted_entry_occur_before_the_prefix_entry.nil? # ================================================================= # # We can report this here to the user, but it is a bit pointless # and spammy to do so, so it was disabled again. # ================================================================= # # e 'In the file '+sfile(target_yaml_file)+': either prefix: '\ # 'or keep_extracted: is missing.' end if does_the_keep_extracted_entry_occur_before_the_prefix_entry e 'In the file '+sfile(target_yaml_file)+':' e e crimson('The keep_extracted: entry occurs before the prefix: entry.') e crimson('This is discouraged and should be changed.') if is_on_roebe open_this_file_with_default_delay(target_yaml_file) end end end } end