Service
The Syntax plugin simply checks all Ruby code for syntax errors. It’s a rather trivial tool, and is here simply for example sake.
Verify syntax of ruby scripts.
This takes one option :scripts which is a glob or list of globs of the scripts to check. By default this is all scripts in the libpath(s).
# File lib/plugins/syckle/syntax.rb, line 44 def analyize #loadpath = options['loadpath'] || loadpath() #exclude = options['exclude'] || exclude() loadpath = self.loadpath.to_list exclude = self.exclude.to_list files = multiglob_r(*loadpath) - multiglob_r(exclude) files = files.select{ |f| File.extname(f) == '.rb' } max = files.collect{ |f| f.size }.max list = [] logfile = project.log + 'syntax.log' if logfile.outofdate?(*files) or force? io.puts "Started" start = Time.now files.each do |file| pass = syntax_check_file(file, max) list << file if !pass end io.puts "\nFinished in %.6f seconds." % [Time.now - start] io.puts "\n#{list.size} Syntax Errors" log_syntax_errors(list) else io.puts "Syntax check is up to date." end end
# File lib/plugins/syckle/syntax.rb, line 29 def exclude=(x) @exclude = x.to_list end
# File lib/plugins/syckle/syntax.rb, line 34 def initialize_defaults @loadpath = metadata.loadpath @exclude = [] end
# File lib/plugins/syckle/syntax.rb, line 24 def loadpath=(x) @loadpath = x.to_list end
# File lib/plugins/syckle/syntax.rb, line 103 def log_syntax_errors(list) logfile = project.log + 'syntax.log' if list.empty? logfile.write('') #logfile.clear else io.puts "\n-- Syntax Errors --\n" list.each do |file| io.print "* #{file}" err = `ruby -c -I#{libsI} #{file} 2>&1` io.puts(err) if verbose? logfile.write("=== #{file}\n#{err}\n\n") end end end
# File lib/plugins/syckle/syntax.rb, line 78 def syntax_check_file(file, max=nil) return unless File.file?(file) max = max || file.size + 2 #libs = loadpath.join(';') #r = system "ruby -c -Ibin:lib:test #{s} &> /dev/null" r = system "ruby -c -I#{libsI} #{file} > /dev/null 2>&1" if r if verbose? io.printline("%-#{max}s" % file, "[PASS]") else io.print '.' end true else if verbose? io.printline("%-#{max}s" % file, "[FAIL]") #puts("%-#{max}s [FAIL]" % [s]) else io.print 'E' end false end end
Generated with the Darkfish Rdoc Generator 2.