Class: ActiverecordCallbackLens::Resolver::MethodResolver::DefLocator

Inherits:
Prism::Visitor
  • Object
show all
Defined in:
lib/activerecord_callback_lens/resolver/method_resolver.rb

Overview

A Prism visitor that captures the body of the DefNode matching a target line (and, when available, a target method name). Mirrors ConditionParser’s LambdaLocator but targets ‘def` definitions rather than lambdas/blocks.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target_line:, method_name: nil) ⇒ DefLocator

Returns a new instance of DefLocator.

Parameters:

  • target_line (Integer)

    the line source_location reports for the def

  • method_name (Symbol, nil) (defaults to: nil)

    the method name to disambiguate overloads



218
219
220
221
222
223
# File 'lib/activerecord_callback_lens/resolver/method_resolver.rb', line 218

def initialize(target_line:, method_name: nil)
  @target_line = target_line
  @method_name = method_name
  @node = nil
  super()
end

Instance Attribute Details

#nodePrism::Node? (readonly)

Returns the body of the matched DefNode.

Returns:

  • (Prism::Node, nil)

    the body of the matched DefNode



214
215
216
# File 'lib/activerecord_callback_lens/resolver/method_resolver.rb', line 214

def node
  @node
end

Instance Method Details

#visit_def_node(def_node) ⇒ void

This method returns an undefined value.

Parameters:

  • def_node (Prism::DefNode)


227
228
229
230
# File 'lib/activerecord_callback_lens/resolver/method_resolver.rb', line 227

def visit_def_node(def_node)
  capture(def_node)
  super
end