Sha256: 19e1456dd1a877001e834fe46c9cba1cfcf189f97b4d5b9501078ec31d5959e8

Contents?: true

Size: 1.39 KB

Versions: 4

Compression:

Stored size: 1.39 KB

Contents

# typed: strict
# frozen_string_literal: true

module Spoom
  module Deadcode
    module Plugins
      class ActiveModel < Base
        extend T::Sig

        ignore_classes_inheriting_from("ActiveModel::EachValidator")
        ignore_methods_named("validate_each", "persisted?")

        sig { override.params(send: Send).void }
        def on_send(send)
          return if send.recv

          case send.name
          when "attribute", "attributes"
            send.each_arg(Prism::SymbolNode) do |arg|
              @index.reference_method(arg.unescaped, send.location)
            end
          when "validate", "validates", "validates!", "validates_each"
            send.each_arg(Prism::SymbolNode) do |arg|
              @index.reference_method(arg.unescaped, send.location)
            end
            send.each_arg_assoc do |key, value|
              key = key.slice.delete_suffix(":")

              case key
              when "if", "unless"
                @index.reference_method(value.slice.delete_prefix(":"), send.location) if value
              else
                @index.reference_constant(camelize(key), send.location)
              end
            end
          when "validates_with"
            arg = send.args.first
            if arg.is_a?(Prism::SymbolNode)
              @index.reference_constant(arg.unescaped, send.location)
            end
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
spoom-1.5.0 lib/spoom/deadcode/plugins/active_model.rb
spoom-1.4.2 lib/spoom/deadcode/plugins/active_model.rb
spoom-1.4.1 lib/spoom/deadcode/plugins/active_model.rb
spoom-1.4.0 lib/spoom/deadcode/plugins/active_model.rb