Class: Fast::Scan

Inherits:
Object
  • Object
show all
Defined in:
lib/fast/scan.rb

Constant Summary collapse

GROUPS =
{
  models: 'Models',
  controllers: 'Controllers',
  services: 'Services',
  jobs: 'Jobs',
  mailers: 'Mailers',
  libraries: 'Libraries',
  other: 'Other'
}.freeze
MAX_METHODS =
5
MAX_SIGNALS =
4
MAX_MACROS =
3

Instance Method Summary collapse

Constructor Details

#initialize(locations, command_name: '.scan', level: nil) ⇒ Scan

Returns a new instance of Scan.



19
20
21
22
23
# File 'lib/fast/scan.rb', line 19

def initialize(locations, command_name: '.scan', level: nil)
  @locations = Array(locations)
  @command_name = command_name
  @level = normalize_level(level)
end

Instance Method Details

#scanObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/fast/scan.rb', line 25

def scan
  files = Fast.ruby_files_from(*@locations)
  grouped = files.each_with_object(Hash.new { |hash, key| hash[key] = [] }) do |file, memo|
    begin
      entries = flatten_entries(Fast.summary(IO.read(file), file: file, command_name: @command_name).outline)
      next if entries.empty?

      memo[classify(file, entries)] << [file, entries]
    rescue StandardError => e
      warn "Error scanning #{file}: #{e.message}" if Fast.debugging
    end
  end

  print_grouped(grouped)
end