Class: FixtureKit::Analyzer::AstFactoryDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/fixture_kit/analyzer/ast_factory_detector.rb

Constant Summary collapse

FACTORY_METHODS =
%w[create build build_stubbed create_list build_list].to_set.freeze

Instance Method Summary collapse

Constructor Details

#initializeAstFactoryDetector

Returns a new instance of AstFactoryDetector.



11
12
13
# File 'lib/fixture_kit/analyzer/ast_factory_detector.rb', line 11

def initialize
  @file_cache = {}
end

Instance Method Details

#detect(mod, method_name) ⇒ Object

Returns array of factory name strings, e.g. [“company”, “employee”]



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fixture_kit/analyzer/ast_factory_detector.rb', line 16

def detect(mod, method_name)
  meth = mod.instance_method(method_name)
  file, line = meth.source_location
  return [] unless file && File.exist?(file)

  ast = parse_file(file)
  block = find_block_at_line(ast, line)
  return [] unless block

  collect_factory_calls(block)
rescue
  []
end