Class: Spoom::Deadcode::Plugins::Ruby

Inherits:
Base
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/spoom/deadcode/plugins/ruby.rb

Instance Method Summary collapse

Methods inherited from Base

ignore_method_names, #on_define_accessor, #on_define_class, #on_define_constant, #on_define_method, #on_define_module

Instance Method Details

#on_send(indexer, send) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/spoom/deadcode/plugins/ruby.rb', line 24

def on_send(indexer, send)
  case send.name
  when "const_defined?", "const_get", "const_source_location"
    reference_symbol_as_constant(indexer, send, T.must(send.args.first))
  when "send", "__send__", "try"
    reference_send_first_symbol_as_method(indexer, send)
  when "alias_method"
    last_arg = send.args.last

    name = case last_arg
    when SyntaxTree::SymbolLiteral
      indexer.node_string(last_arg.value)
    when SyntaxTree::StringLiteral
      last_arg.parts.map { |part| indexer.node_string(part) }.join
    end

    return unless name

    indexer.reference_method(name, send.node)
  end
end