Class: Spoom::Deadcode::Plugins::ActionPack

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

Constant Summary collapse

CALLBACKS =
T.let(
  [
    "after_action",
    "append_after_action",
    "append_around_action",
    "append_before_action",
    "around_action",
    "before_action",
    "prepend_after_action",
    "prepend_around_action",
    "prepend_before_action",
    "skip_after_action",
    "skip_around_action",
    "skip_before_action",
  ].freeze,
  T::Array[String],
)

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_module

Instance Method Details

#on_define_method(indexer, definition) ⇒ Object



31
32
33
# File 'lib/spoom/deadcode/plugins/actionpack.rb', line 31

def on_define_method(indexer, definition)
  definition.ignored! if ignored_class_name?(indexer.nesting_class_name)
end

#on_send(indexer, send) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/spoom/deadcode/plugins/actionpack.rb', line 36

def on_send(indexer, send)
  return unless send.recv.nil? && CALLBACKS.include?(send.name)

  arg = send.args.first
  case arg
  when SyntaxTree::SymbolLiteral
    indexer.reference_method(indexer.node_string(arg.value), send.node)
  when SyntaxTree::VarRef
    indexer.reference_constant(indexer.node_string(arg), 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
end