Class: Spoom::Deadcode::Plugins::ActiveModel

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

Instance Method Summary collapse

Methods inherited from Base

ignore_classes_inheriting_from, ignore_classes_named, ignore_constants_named, ignore_methods_named, ignore_modules_named, #internal_on_define_accessor, #internal_on_define_class, #internal_on_define_constant, #internal_on_define_method, #internal_on_define_module, #internal_on_send, #on_define_accessor, #on_define_class, #on_define_constant, #on_define_method, #on_define_module

Instance Method Details

#on_send(indexer, send) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/spoom/deadcode/plugins/active_model.rb', line 14

def on_send(indexer, send)
  return if send.recv

  case send.name
  when "attribute", "attributes"
    send.each_arg(SyntaxTree::SymbolLiteral) do |arg|
      indexer.reference_method(indexer.node_string(arg.value), send.node)
    end
  when "validate", "validates", "validates!", "validates_each"
    send.each_arg(SyntaxTree::SymbolLiteral) do |arg|
      indexer.reference_method(indexer.node_string(arg.value), send.node)
    end
    send.each_arg_assoc do |key, value|
      key = indexer.node_string(key).delete_suffix(":")

      case key
      when "if", "unless"
        indexer.reference_method(indexer.symbol_string(value), send.node) if value
      else
        indexer.reference_constant(camelize(key), send.node)
      end
    end
  when "validates_with"
    arg = send.args.first
    if arg.is_a?(SyntaxTree::SymbolLiteral)
      indexer.reference_constant(indexer.node_string(arg.value), send.node)
    end
  end
end