class Pronto::Flay
Constants
- DEFAULT_SEVERITY_LEVELS
Public Instance Methods
Source
# File lib/pronto/flay.rb, line 74 def custom_severity_levels_config Pronto::ConfigFile.new.to_h.dig('flay', 'severity_levels') || {} end
Source
# File lib/pronto/flay.rb, line 32 def files @files ||= ruby_patches.map(&:new_file_full_path) end
Source
Source
# File lib/pronto/flay.rb, line 60 def level(hash) same?(hash) ? severity_levels_config[:identical] : severity_levels_config[:similar] end
Source
# File lib/pronto/flay.rb, line 103 def mass_threshold @mass_threshold ||= ENV['PRONTO_FLAY_MASS_THRESHOLD'] || Pronto::ConfigFile.new.to_h.dig('flay', 'mass_threshold') || ::Flay.default_options[:mass].to_s end
Source
# File lib/pronto/flay.rb, line 78 def message(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
Source
# File lib/pronto/flay.rb, line 36 def messages nodes.map do |node| patch = patch_for_node(node) line = patch.added_lines.find do |added_line| added_line.new_lineno == node.line end new_message(line, node) if line end.flatten.compact end
Source
# File lib/pronto/flay.rb, line 54 def new_message(line, node) path = line.patch.delta.new_file[:path] hash = node.structural_hash Message.new(path, line, level(hash), message(hash), nil, self.class) end
Source
# File lib/pronto/flay.rb, line 91 def nodes result = [] masses.keys.each do |hash| nodes_for(hash).each { |node| result << node } end result end
Source
# File lib/pronto/flay.rb, line 87 def nodes_for(hash) flay.hashes[hash] end
Source
# File lib/pronto/flay.rb, line 48 def patch_for_node(node) ruby_patches.find do |patch| patch.new_file_full_path.to_s == node.file.to_s end end
Source
# File lib/pronto/flay.rb, line 11 def run if files.any? flay.analyze messages else [] end end
Source
# File lib/pronto/flay.rb, line 68 def severity_levels_config @severity_levels_config ||= DEFAULT_SEVERITY_LEVELS.merge(custom_severity_levels_config) .map { |k, v| [k.to_sym, v.to_sym] } .to_h end