class RBT::Cookbooks::CheckValidityOfCookbooks
Constants
- NAMESPACE
#¶ ↑
NAMESPACE
¶ ↑#¶ ↑
Public Class Methods
new( name_of_the_program_to_check = ARGV, run_already = true ) { || ... }
click to toggle source
#¶ ↑
initialize¶ ↑
#¶ ↑
# File lib/rbt/validation/check_validity_of_cookbooks.rb, line 62 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 when :be_verbose @be_verbose = true 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
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/validation/check_validity_of_cookbooks.rb, line 127 def work_on_each_file( i = available_files? ) i.each {|file| program_short_name = File.basename(file).sub(/\.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 http://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 !dataset.include?('use_this_program_name') and !dataset.include?('use_this_program_name_on_gobolinux') regex_to_use = /^ program_name: ([a-zA-Z\-_\d\.]+)$/ # See: http://rubular.com/r/TK5ceX1woW 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 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 opnn; e 'Neither "program_name:" nor an "url1:" entry were '\ 'found for `'+simp(file)+'`.' opnn; e '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 opnn; e "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. # =================================================================== # opnn; e "We found an invalid program file at #{sfile(file)}." opnn; e "The names are not the same: #{orange(a)} != #{orange(b)}." end } end