Class: Pronto::Flay
- Inherits:
-
Runner
- Object
- Runner
- Pronto::Flay
- Defined in:
- lib/pronto/flay.rb
Instance Method Summary collapse
- #files ⇒ Object
-
#flay ⇒ Object
The current Flay (2.8.0) takes care of filtering files by looking at .flayignore.
- #level(hash) ⇒ Object
- #masses ⇒ Object
- #message(hash) ⇒ Object
- #messages ⇒ Object
- #new_message(line, node) ⇒ Object
- #nodes ⇒ Object
- #nodes_for(hash) ⇒ Object
- #patch_for_node(node) ⇒ Object
- #run ⇒ Object
- #same?(hash) ⇒ Boolean
Instance Method Details
#files ⇒ Object
23 24 25 |
# File 'lib/pronto/flay.rb', line 23 def files @files ||= ruby_patches.map(&:new_file_full_path) end |
#flay ⇒ Object
The current Flay (2.8.0) takes care of filtering files by looking at .flayignore. Saving the returned Flay object at @flay so we can inspect it and build the messages Array.
19 20 21 |
# File 'lib/pronto/flay.rb', line 19 def flay @flay ||= ::Flay.run(files) end |
#level(hash) ⇒ Object
51 52 53 |
# File 'lib/pronto/flay.rb', line 51 def level(hash) same?(hash) ? :error : :warning end |
#masses ⇒ Object
80 81 82 |
# File 'lib/pronto/flay.rb', line 80 def masses flay.masses end |
#message(hash) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/pronto/flay.rb', line 59 def (hash) match = same?(hash) ? 'Identical' : 'Similar' location = nodes_for(hash).map do |node| "#{File.basename(node.file)}:#{node.line}" end "#{match} code found in #{location.join(', ')} (mass = #{masses[hash]})" end |
#messages ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/pronto/flay.rb', line 27 def nodes.map do |node| patch = patch_for_node(node) line = patch.added_lines.find do |added_line| added_line.new_lineno == node.line end (line, node) if line end.flatten.compact end |
#new_message(line, node) ⇒ Object
45 46 47 48 49 |
# File 'lib/pronto/flay.rb', line 45 def (line, node) path = line.patch.delta.new_file[:path] hash = node.structural_hash Message.new(path, line, level(hash), (hash), nil, self.class) end |
#nodes ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/pronto/flay.rb', line 72 def nodes result = [] masses.keys.each do |hash| nodes_for(hash).each { |node| result << node } end result end |
#nodes_for(hash) ⇒ Object
68 69 70 |
# File 'lib/pronto/flay.rb', line 68 def nodes_for(hash) flay.hashes[hash] end |
#patch_for_node(node) ⇒ Object
39 40 41 42 43 |
# File 'lib/pronto/flay.rb', line 39 def patch_for_node(node) ruby_patches.find do |patch| patch.new_file_full_path == node.file end end |
#run ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/pronto/flay.rb', line 6 def run if files.any? flay.analyze else [] end end |
#same?(hash) ⇒ Boolean
55 56 57 |
# File 'lib/pronto/flay.rb', line 55 def same?(hash) flay.identical[hash] end |