Class: Necropsy::AstScanner

Inherits:
Object
  • Object
show all
Defined in:
lib/necropsy/ast_scanner.rb,
lib/necropsy/ast_scanner/traversal.rb,
lib/necropsy/ast_scanner/dsl_macros.rb,
lib/necropsy/ast_scanner/references.rb,
lib/necropsy/ast_scanner/call_recording.rb,
lib/necropsy/ast_scanner/ruby_semantics.rb,
lib/necropsy/ast_scanner/value_definitions.rb,
lib/necropsy/ast_scanner/method_definitions.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_validation after_validation before_save after_save around_save
  around_validation before_touch after_touch
  before_create after_create around_create before_update after_update around_update
  before_destroy after_destroy around_destroy after_commit after_rollback after_initialize after_find
  after_create_commit after_update_commit after_destroy_commit after_save_commit
  validate rescue_from helper_method
].freeze
VISIBILITY_MACROS =
%i[public protected private public_class_method private_class_method].freeze
SYMBOL_REFERENCE_CALLS =
%i[method respond_to? try try!].freeze
RAILS_BUILTIN_VALIDATORS =
%w[
  absence acceptance allow_blank allow_nil comparison confirmation exclusion format if inclusion length message numericality
  on presence strict uniqueness unless
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(project:, files:) ⇒ AstScanner

Returns a new instance of AstScanner.



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/necropsy/ast_scanner.rb', line 50

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 = []
  @factory_methods = project.config.factory_methods.to_set(&:to_s)
end

Instance Method Details

#scanObject



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/necropsy/ast_scanner.rb', line 62

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