Class: RubyParserGauntlet
- Inherits:
-
Gauntlet
- Object
- Gauntlet
- RubyParserGauntlet
- Defined in:
- lib/gauntlet_rubyparser.rb
Instance Method Summary collapse
- #broke(name, file, msg) ⇒ Object
- #diff_pp(o1, o2) ⇒ Object
-
#initialize ⇒ RubyParserGauntlet
constructor
A new instance of RubyParserGauntlet.
- #process(path, name) ⇒ Object
- #run(name) ⇒ Object
- #should_skip?(name) ⇒ Boolean
Constructor Details
#initialize ⇒ RubyParserGauntlet
Returns a new instance of RubyParserGauntlet.
15 16 17 18 19 20 21 |
# File 'lib/gauntlet_rubyparser.rb', line 15 def initialize super self.data = Hash.new { |h,k| h[k] = {} } old_data = load_yaml data_file self.data.merge! old_data end |
Instance Method Details
#broke(name, file, msg) ⇒ Object
49 50 51 52 53 |
# File 'lib/gauntlet_rubyparser.rb', line 49 def broke name, file, msg warn "bad" self.data[name][file] = msg self.dirty = true end |
#diff_pp(o1, o2) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/gauntlet_rubyparser.rb', line 35 def diff_pp o1, o2 require 'pp' Tempfile.new('ruby_parser_a') do |file_a| PP.pp o1, file_a Tempfile.new('ruby_parser_b') do |file_b| PP.pp o2, file_b `diff -u #{file_a.path} #{file_b.path}` end end end |
#process(path, name) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/gauntlet_rubyparser.rb', line 55 def process path, name begin $stderr.print " #{path}: " rp = RubyParser.new r2r = Ruby2Ruby.new old_ruby = File.read(path) begin old_sexp = rp.process old_ruby rescue Racc::ParseError => e self.data[name][path] = :unparsable self.dirty = true return end new_ruby = r2r.process old_sexp.deep_clone begin new_sexp = rp.process new_ruby rescue Racc::ParseError => e broke name, path, "couldn't parse new_ruby: #{e..strip}" return end if old_sexp != new_sexp then broke name, path, diff_pp(old_sexp, new_sexp) return end self.data[name][path] = true self.dirty = true warn "good" rescue Interrupt puts "User cancelled" exit 1 rescue Exception => e broke name, path, " UNKNOWN ERROR: #{e}: #{e..strip}" end end |
#run(name) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/gauntlet_rubyparser.rb', line 97 def run name warn name Dir["**/*.rb"].sort.each do |path| next if path =~ /gemspec.rb/ # HACK next if data[name][path] == true process path, name end if self.data[name].values.all? { |v| v == true } then warn " ALL GOOD!" self.data[name] = true self.dirty = true end end |
#should_skip?(name) ⇒ Boolean
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/gauntlet_rubyparser.rb', line 23 def should_skip? name if $f then if Hash === data[name] then ! data[name].empty? else data[name] end else data[name] == true # yes, == true on purpose end end |