Class: PuppetCheck
- Inherits:
-
Object
- Object
- PuppetCheck
- Defined in:
- lib/puppet-check.rb
Overview
interfaces from CLI/tasks and to individual parsers
Defined Under Namespace
Class Attribute Summary collapse
-
.clean_files ⇒ Object
Returns the value of attribute clean_files.
-
.error_files ⇒ Object
Returns the value of attribute error_files.
-
.future_parser ⇒ Object
Returns the value of attribute future_parser.
-
.ignored_files ⇒ Object
Returns the value of attribute ignored_files.
-
.puppetlint_args ⇒ Object
Returns the value of attribute puppetlint_args.
-
.rubocop_args ⇒ Object
Returns the value of attribute rubocop_args.
-
.style_check ⇒ Object
Returns the value of attribute style_check.
-
.warning_files ⇒ Object
Returns the value of attribute warning_files.
Class Method Summary collapse
-
.output_results ⇒ Object
output the results for the files that were requested to be checked.
Instance Method Summary collapse
-
#execute_parsers(files) ⇒ Object
categorize and pass the files out to the parsers to determine their status.
-
#parse_paths(paths) ⇒ Object
parse the paths and return the array of files.
-
#run(paths) ⇒ Object
main runner for PuppetCheck.
Class Attribute Details
.clean_files ⇒ Object
Returns the value of attribute clean_files.
23 24 25 |
# File 'lib/puppet-check.rb', line 23 def clean_files @clean_files end |
.error_files ⇒ Object
Returns the value of attribute error_files.
23 24 25 |
# File 'lib/puppet-check.rb', line 23 def error_files @error_files end |
.future_parser ⇒ Object
Returns the value of attribute future_parser.
23 24 25 |
# File 'lib/puppet-check.rb', line 23 def future_parser @future_parser end |
.ignored_files ⇒ Object
Returns the value of attribute ignored_files.
23 24 25 |
# File 'lib/puppet-check.rb', line 23 def ignored_files @ignored_files end |
.puppetlint_args ⇒ Object
Returns the value of attribute puppetlint_args.
23 24 25 |
# File 'lib/puppet-check.rb', line 23 def puppetlint_args @puppetlint_args end |
.rubocop_args ⇒ Object
Returns the value of attribute rubocop_args.
23 24 25 |
# File 'lib/puppet-check.rb', line 23 def rubocop_args @rubocop_args end |
.style_check ⇒ Object
Returns the value of attribute style_check.
23 24 25 |
# File 'lib/puppet-check.rb', line 23 def style_check @style_check end |
.warning_files ⇒ Object
Returns the value of attribute warning_files.
23 24 25 |
# File 'lib/puppet-check.rb', line 23 def warning_files @warning_files end |
Class Method Details
.output_results ⇒ Object
output the results for the files that were requested to be checked
80 81 82 83 84 85 |
# File 'lib/puppet-check.rb', line 80 def self.output_results puts "\033[31mThe following files have errors:\033[0m", error_files.join("\n\n") unless error_files.empty? puts "\n\033[33mThe following files have warnings:\033[0m", warning_files.join("\n\n") unless warning_files.empty? puts "\n\033[32mThe following files have no errors or warnings:\033[0m", clean_files unless clean_files.empty? puts "\n\033[34mThe following files have unrecognized formats and therefore were not processed:\033[0m", ignored_files unless ignored_files.empty? end |
Instance Method Details
#execute_parsers(files) ⇒ Object
categorize and pass the files out to the parsers to determine their status
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/puppet-check.rb', line 61 def execute_parsers(files) PuppetParser.manifest(files.select { |file| File.extname(file) == '.pp' }) files.reject! { |file| File.extname(file) == '.pp' } PuppetParser.template(files.select { |file| File.extname(file) == '.epp' }) files.reject! { |file| File.extname(file) == '.epp' } RubyParser.ruby(files.select { |file| File.extname(file) == '.rb' }) files.reject! { |file| File.extname(file) == '.rb' } RubyParser.template(files.select { |file| File.extname(file) == '.erb' }) files.reject! { |file| File.extname(file) == '.erb' } DataParser.yaml(files.select { |file| file =~ /.*\.ya?ml$/ }) files.reject! { |file| file =~ /.*\.ya?ml$/ } DataParser.json(files.select { |file| File.extname(file) == '.json' }) files.reject! { |file| File.extname(file) == '.json' } RubyParser.librarian(files.select { |file| file =~ /.*(Puppet|Module|Rake|Gem)file$/ }) files.reject! { |file| file =~ /.*(?:Puppet|Module|Rake|Gem)file$/ } files.each { |file| self.class.ignored_files.push("-- #{file}") } end |
#parse_paths(paths) ⇒ Object
parse the paths and return the array of files
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/puppet-check.rb', line 42 def parse_paths(paths) files = [] # traverse the unique paths, return all files, and replace // with / paths.uniq.each do |path| if File.directory?(path) files.concat(Dir.glob("#{path}/**/*").select { |subpath| File.file? subpath }) elsif File.file?(path) files.push(path) end end # check that at least one file was found, remove double slashes, and return unique files raise "No files found in supplied paths #{paths.join(', ')}." if files.empty? files.map! { |file| file.gsub('//', '/') } files.uniq end |
#run(paths) ⇒ Object
main runner for PuppetCheck
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/puppet-check.rb', line 27 def run(paths) # grab all of the files to be processed files = parse_paths(paths) # parse the files execute_parsers(files) # output the diagnostic results self.class.output_results # exit code self.class.error_files.empty? ? 0 : 1 end |