Class: Spoom::Deadcode::Plugins::ActiveRecord
- Defined in:
- lib/spoom/deadcode/plugins/active_record.rb
Constant Summary collapse
- CALLBACKS =
[ "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
- CRUD_METHODS =
: Array
[ "assign_attributes", "create", "create!", "insert", "insert!", "new", "update", "update!", "upsert", ].freeze
- ARRAY_METHODS =
: Array
[ "insert_all", "insert_all!", "upsert_all", ].freeze
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#on_send(send) ⇒ Object
: (Send send) -> void.
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
: (Send send) -> void
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/spoom/deadcode/plugins/active_record.rb', line 64 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 |