class RBT::Cookbooks::CheckValidityOfCookbooks
Public Class Methods
new( name_of_the_program_to_check = ARGV, run_already = true ) { || ... }
click to toggle source
#¶ ↑
initialize¶ ↑
#¶ ↑
# File lib/rbt/checks_and_validations/check_validity_of_cookbooks.rb, line 54 def initialize( name_of_the_program_to_check = ARGV, run_already = true ) reset unless name_of_the_program_to_check.empty? set_available_files(name_of_the_program_to_check) end if block_given? yielded = yield case yielded # === :be_verbose when :be_verbose set_be_verbose end end run if run_already end
Public Instance Methods
available_files?()
click to toggle source
hash?()
click to toggle source
obtain_all_available_files()
click to toggle source
reset()
click to toggle source
#¶ ↑
reset¶ ↑
#¶ ↑
Calls superclass method
RBT::Base#reset
# File lib/rbt/checks_and_validations/check_validity_of_cookbooks.rb, line 76 def reset super() infer_the_namespace # ======================================================================= # # === @hash # ======================================================================= # @hash = {} # ======================================================================= # # === :be_verbose # ======================================================================= # set_be_quiet # By default, this class is not very verbose. obtain_all_available_files # Must come after @hash. end
run()
click to toggle source
set_available_files(i)
click to toggle source
work_on_each_file( i = available_files? )
click to toggle source
#¶ ↑
work_on_each_file
¶ ↑
The input should be an Array.
#¶ ↑
# File lib/rbt/checks_and_validations/check_validity_of_cookbooks.rb, line 126 def work_on_each_file( i = available_files? ) i.each {|file| program_short_name = File.basename(file). delete_suffix('.yml') # ===================================================================== # # Ok, read in the dataset next. We assume that the input is either # a file or a string. # ===================================================================== # possible_location_of_the_yaml_file = "#{individual_cookbooks_dir?}#{program_short_name}.yml" if File.exist? possible_location_of_the_yaml_file dataset = File.read(possible_location_of_the_yaml_file) else dataset = file end # ===================================================================== # # Now we determine "component a", which is the program name. # ===================================================================== # regex_to_use = /^(\w+):/ # See https://rubular.com/r/8hKCAYXZqY dataset =~ regex_to_use a = $1.to_s.dup # ===================================================================== # # Next, we grab the entry for "b". This can work if we have an entry # called url1, or a program_name. Since the entry program_name is # more important, we will check on it first. # ===================================================================== # if dataset.include?('program_name_and_program_version') and !dataset.include?('use_this_program_name') and !dataset.include?('use_this_program_name_on_gobolinux') regex_to_use = /^ program_name_and_program_version: ([a-zA-Z\-_\d\.]+)$/ # See: https://rubular.com/r/AVdsMgDyme1qvw dataset =~ regex_to_use b = $1.to_s.dup case b # case tag when 'URL_REPLACE_UNDERSCORE', 'URL_CONVERT_UNDERSCORE', 'USE_URL_SANITIZED', 'USE_URL_DOWNCASE', 'USE_URL' b = program_short_name # =================================================================== # # === FIRST_UNDERSCORE_IS_HYPHEN # =================================================================== # when 'FIRST_UNDERSCORE_IS_HYPHEN' b = File.basename(url1?) end b = ProgramInformation.return_real_short_name(b.strip) if b b.chop! if b.end_with?('-') b.delete!('-') if b.include? '-' end # ===================================================================== # # Ok, now we can check for the url1 entry, as there was no entry # called program_name in that particular yaml file. # ===================================================================== # elsif dataset.include? 'url1' regex_to_use = /^ url1: (.+)\w/ # See: http://rubular.com/r/SOdBdhGXgw dataset =~ regex_to_use b = $1.to_s.dup # =================================================================== # # Ok, we still have to do some sanitizing to do, such as ignoring # all past a '#' token: # =================================================================== # if b.include? '#' b = b[0..b.index('#')] end if b.include? 'URL_REPLACE_UNDERSCORE' b = program_short_name else b = ProgramInformation.return_real_short_name(b.strip) b = b.first.downcase if b.is_a? Array end else opne 'Neither "program_name:" nor an "url1:" entry were '\ 'found for `'+simp(file)+'`.' opne 'This is not allowed, thus we will exit now.' exit end a.downcase! b.downcase! b.delete!('.') if b.include? '.' if a == b # Everything is ok here, thus we do not have to report anything at all in this case. if be_verbose? opne "All is fine for the program "\ "`#{royalblue(program_short_name)}`." end # ^^^ Enabling the above by default may be too verbose. else # =================================================================== # # Compare the two names. # =================================================================== # opne "We found an invalid program file at #{sfile(file)}." opne "The names are not the same: #{orange(a)} != #{orange(b)}." end } end