Class: Txray::Scanner
- Inherits:
-
Object
- Object
- Txray::Scanner
- Defined in:
- lib/txray/scanner.rb
Instance Method Summary collapse
- #analyze(sources) ⇒ Object
- #dedupe(offenses) ⇒ Object
- #files ⇒ Object
-
#initialize(config, paths: nil) ⇒ Scanner
constructor
A new instance of Scanner.
- #run ⇒ Object
Constructor Details
#initialize(config, paths: nil) ⇒ Scanner
Returns a new instance of Scanner.
11 12 13 14 |
# File 'lib/txray/scanner.rb', line 11 def initialize(config, paths: nil) @config = config @paths = Array(paths).reject(&:empty?) end |
Instance Method Details
#analyze(sources) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/txray/scanner.rb', line 27 def analyze(sources) index = MethodIndex.new clients = ClientIndex.new(Classifier.new(@config)) sources.each do |source| index.index(source) clients.index(source) end analyzer = Analyzer.new(index: index, clients: clients, config: @config) dedupe(sources.flat_map { |source| analyzer.call(source) }).sort_by(&:sort_key) end |
#dedupe(offenses) ⇒ Object
39 40 41 |
# File 'lib/txray/scanner.rb', line 39 def dedupe(offenses) offenses.group_by(&:key).values.map { |group| group.min_by { |offense| offense.trace.size } } end |
#files ⇒ Object
43 44 45 46 47 48 |
# File 'lib/txray/scanner.rb', line 43 def files roots = @paths.empty? ? @config.includes : @paths verify(roots) unless @paths.empty? roots.flat_map { |root| (root).reject { |path| excluded?(path, root) } } .map { |path| relative(path) }.uniq.sort end |
#run ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/txray/scanner.rb', line 16 def run sources = [] skipped = [] files.each do |path| source = SourceFile.parse(path) source ? sources << source : skipped << path end Result.new(offenses: analyze(sources), files: sources.map(&:path), skipped: skipped) end |