Class: Insta::Inline::CallFinder

Inherits:
Prism::Visitor
  • Object
show all
Defined in:
lib/insta/inline/call_finder.rb,
sig/insta/inline/call_finder.rbs

Constant Summary collapse

METHODS =

: Array

Returns:

  • (Array[Symbol])
[:assert_inline_snapshot, :match_inline_snapshot].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target_line) ⇒ CallFinder

: (Integer) -> void

Parameters:

  • (Integer)


13
14
15
16
17
18
# File 'lib/insta/inline/call_finder.rb', line 13

def initialize(target_line)
  super()

  @target_line = target_line
  @found_call = nil
end

Instance Attribute Details

#found_callPrism::CallNode? (readonly)

: Prism::CallNode?

Returns:

  • (Prism::CallNode, nil)


10
11
12
# File 'lib/insta/inline/call_finder.rb', line 10

def found_call
  @found_call
end

Instance Method Details

#covers_line?(node) ⇒ Boolean

: (Prism::Node) -> bool

Parameters:

  • (Prism::Node)

Returns:

  • (Boolean)


30
31
32
33
34
# File 'lib/insta/inline/call_finder.rb', line 30

def covers_line?(node)
  location = node.location

  @target_line.between?(location.start_line, location.end_line)
end

#visit_call_node(node) ⇒ void

This method returns an undefined value.

: (Prism::CallNode) -> void

Parameters:

  • (Prism::CallNode)


21
22
23
24
25
# File 'lib/insta/inline/call_finder.rb', line 21

def visit_call_node(node)
  @found_call = node if METHODS.include?(node.name) && covers_line?(node)

  super
end