Class: StudFinder::RailsInference

Inherits:
Object
  • Object
show all
Defined in:
lib/stud_finder/rails_inference.rb

Overview

Extracts conservative Rails-style implicit constant references from Ruby ASTs.

Defined Under Namespace

Classes: Inference

Constant Summary collapse

ASSOCIATIONS =
%i[belongs_to has_one has_many has_and_belongs_to_many].freeze
COLLECTION_ASSOCIATIONS =
%i[has_many has_and_belongs_to_many].freeze
STRING_CONSTANTIZERS =
%i[constantize safe_constantize].freeze
SAFE_CLASS_BODY_WRAPPERS =
%i[with_options included class_eval class_exec].freeze
IRREGULAR_SINGULARS =
{
  'people' => 'person',
  'children' => 'child',
  'men' => 'man',
  'women' => 'woman',
  'mice' => 'mouse',
  'geese' => 'goose'
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(ast) ⇒ RailsInference

Returns a new instance of RailsInference.



21
22
23
# File 'lib/stud_finder/rails_inference.rb', line 21

def initialize(ast)
  @ast = ast
end

Instance Method Details

#callObject



25
26
27
28
29
30
31
# File 'lib/stud_finder/rails_inference.rb', line 25

def call
  return [] unless @ast

  @ast.each_node(:send).filter_map do |node|
    association_inference(node) || string_constant_inference(node)
  end
end