Class: ActiverecordCallbackLens::Parser::ConditionParser::LambdaLocator

Inherits:
Prism::Visitor
  • Object
show all
Defined in:
lib/activerecord_callback_lens/parser/condition_parser.rb

Overview

A Prism visitor that captures the innermost LambdaNode or BlockNode whose source range encloses a target line. Used to isolate a single proc’s body from the surrounding file AST.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target_line:) ⇒ LambdaLocator

Returns a new instance of LambdaLocator.

Parameters:

  • target_line (Integer)

    the line the proc’s source_location reports



136
137
138
139
140
# File 'lib/activerecord_callback_lens/parser/condition_parser.rb', line 136

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

Instance Attribute Details

#nodePrism::Node? (readonly)

Returns the body of the innermost matching lambda/block.

Returns:

  • (Prism::Node, nil)

    the body of the innermost matching lambda/block



133
134
135
# File 'lib/activerecord_callback_lens/parser/condition_parser.rb', line 133

def node
  @node
end

Instance Method Details

#visit_block_node(block_node) ⇒ void

This method returns an undefined value.

Parameters:

  • block_node (Prism::BlockNode)


151
152
153
154
# File 'lib/activerecord_callback_lens/parser/condition_parser.rb', line 151

def visit_block_node(block_node)
  capture(block_node)
  super
end

#visit_lambda_node(lambda_node) ⇒ void

This method returns an undefined value.

Parameters:

  • lambda_node (Prism::LambdaNode)


144
145
146
147
# File 'lib/activerecord_callback_lens/parser/condition_parser.rb', line 144

def visit_lambda_node(lambda_node)
  capture(lambda_node)
  super
end