Class: Spoom::Deadcode::Plugins::ActiveRecord
- Extended by:
- T::Sig
- Defined in:
- lib/spoom/deadcode/plugins/active_record.rb
Constant Summary collapse
- CALLBACKS =
T.let( [ "after_commit", "after_create_commit", "after_create", "after_destroy_commit", "after_destroy", "after_find", "after_initialize", "after_rollback", "after_save_commit", "after_save", "after_touch", "after_update_commit", "after_update", "after_validation", "around_create", "around_destroy", "around_save", "around_update", "before_create", "before_destroy", "before_save", "before_update", "before_validation", ].freeze, T::Array[String], )
- CRUD_METHODS =
T.let( [ "assign_attributes", "create", "create!", "insert", "insert!", "new", "update", "update!", "upsert", ].freeze, T::Array[String], )
- ARRAY_METHODS =
T.let( [ "insert_all", "insert_all!", "upsert_all", ].freeze, T::Array[String], )
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
ignore_classes_inheriting_from, ignore_classes_named, ignore_constants_named, ignore_methods_named, ignore_modules_named, #initialize, #internal_on_define_accessor, #internal_on_define_class, #internal_on_define_constant, #internal_on_define_method, #internal_on_define_module, #on_define_accessor, #on_define_class, #on_define_constant, #on_define_method, #on_define_module
Constructor Details
This class inherits a constructor from Spoom::Deadcode::Plugins::Base
Instance Method Details
#on_send(send) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/spoom/deadcode/plugins/active_record.rb', line 74 def on_send(send) if send.recv.nil? && CALLBACKS.include?(send.name) send.each_arg(Prism::SymbolNode) do |arg| @index.reference_method(arg.unescaped, send.location) end return end return unless send.recv case send.name when *CRUD_METHODS send.each_arg_assoc do |key, _value| key = key.slice.delete_suffix(":") @index.reference_method("#{key}=", send.location) end when *ARRAY_METHODS send.each_arg(Prism::ArrayNode) do |arg| arg.elements.each do |part| next unless part.is_a?(Prism::HashNode) part.elements.each do |assoc| next unless assoc.is_a?(Prism::AssocNode) key = assoc.key.slice.delete_suffix(":") @index.reference_method("#{key}=", send.location) end end end end end |