Class: Prism::Merge::PartialTemplateNode

Inherits:
Object
  • Object
show all
Defined in:
lib/prism/merge/partial_template_node.rb

Overview

Thin navigable adapter for top-level Prism statements used by PartialTemplateMerger.

The shared navigable substrate expects statement-like objects that expose type, text, and source_position. Prism::Merge::FileAnalysis returns raw Prism nodes (and wrapped frozen nodes) whose native API is richer than that contract but not shaped the same way. This adapter keeps the partial merger thin without changing the full SmartMerger path.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ PartialTemplateNode

Returns a new instance of PartialTemplateNode.



16
17
18
# File 'lib/prism/merge/partial_template_node.rb', line 16

def initialize(node)
  @node = node
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



60
61
62
63
64
# File 'lib/prism/merge/partial_template_node.rb', line 60

def method_missing(method_name, *args, &block)
  return node.public_send(method_name, *args, &block) if node.respond_to?(method_name)

  super
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



14
15
16
# File 'lib/prism/merge/partial_template_node.rb', line 14

def node
  @node
end

Instance Method Details

#end_lineObject



47
48
49
# File 'lib/prism/merge/partial_template_node.rb', line 47

def end_line
  source_position&.dig(:end_line)
end

#inner_nodeObject



55
56
57
58
# File 'lib/prism/merge/partial_template_node.rb', line 55

def inner_node
  n = node.respond_to?(:unwrap) ? node.unwrap : node
  n.respond_to?(:node) ? n.node : n
end

#locationObject



51
52
53
# File 'lib/prism/merge/partial_template_node.rb', line 51

def location
  node.location
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/prism/merge/partial_template_node.rb', line 66

def respond_to_missing?(method_name, include_private = false)
  node.respond_to?(method_name, include_private) || super
end

#source_positionObject



33
34
35
36
37
38
39
40
41
# File 'lib/prism/merge/partial_template_node.rb', line 33

def source_position
  loc = node.location
  return unless loc

  {
    start_line: loc.start_line,
    end_line: loc.end_line
  }
end

#start_lineObject



43
44
45
# File 'lib/prism/merge/partial_template_node.rb', line 43

def start_line
  source_position&.dig(:start_line)
end

#textObject



29
30
31
# File 'lib/prism/merge/partial_template_node.rb', line 29

def text
  node.slice.to_s
end

#typeObject



20
21
22
23
24
25
26
27
# File 'lib/prism/merge/partial_template_node.rb', line 20

def type
  return fallback_type_name unless inner_node.respond_to?(:type)

  ct = NodeTypeNormalizer.canonical_type(inner_node.type, :prism)
  return :call_with_block if ct == :call && inner_node.block

  ct || fallback_type_name
end