Class: Necropsy::AstScanner

Inherits:
Object
  • Object
show all
Defined in:
lib/necropsy/ast_scanner.rb

Defined Under Namespace

Classes: Context

Constant Summary collapse

ATTR_MACROS =
%i[attr_reader attr_writer attr_accessor].freeze
DYNAMIC_SENDS =
%i[send public_send __send__].freeze
MODULE_RELATION_MACROS =
%i[include prepend extend].freeze
RAILS_CALLBACK_MACROS =
%i[
  before_action after_action around_action
  before_save after_save before_create after_create before_update after_update
  before_destroy after_destroy around_save validate
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(project:, files:) ⇒ AstScanner

Returns a new instance of AstScanner.



31
32
33
34
35
36
37
38
39
40
# File 'lib/necropsy/ast_scanner.rb', line 31

def initialize(project:, files:)
  @project = project
  @files = files
  @nodes = []
  @call_sites = []
  @instantiated_classes = Set.new
  @uncertainties = Hash.new { |hash, key| hash[key] = [] }
  @class_data = {}
  @entrypoint_hints = []
end

Instance Method Details

#scanObject



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/necropsy/ast_scanner.rb', line 42

def scan
  files.each { |file| scan_file(file) }
  ScanResult.new(
    nodes: nodes.uniq(&:id),
    call_sites: call_sites,
    instantiated_classes: instantiated_classes,
    uncertainties: uncertainties,
    class_infos: class_infos,
    entrypoint_hints: entrypoint_hints.uniq
  )
end