Class: A11y::Lint::RubyCode

Inherits:
Object
  • Object
show all
Defined in:
lib/a11y/lint/ruby_code.rb

Overview

Represents a Ruby code string extracted from a template. Parses the code with Prism and exposes the resulting CallNode.

Instance Method Summary collapse

Constructor Details

#initialize(code) ⇒ RubyCode

Returns a new instance of RubyCode.



10
11
12
# File 'lib/a11y/lint/ruby_code.rb', line 10

def initialize(code)
  @code = code
end

Instance Method Details

#call_nodeObject

Returns the Prism::CallNode for the outermost receiverless method call in the code, or nil if none exists.



16
17
18
# File 'lib/a11y/lint/ruby_code.rb', line 16

def call_node
  @call_node ||= parse
end

#top_level_call_nodeObject

Returns the outermost CallNode regardless of receiver (e.g. matches ‘form.input(…)`). Used by rules that target method calls on a builder object.



23
24
25
26
27
# File 'lib/a11y/lint/ruby_code.rb', line 23

def top_level_call_node
  return @top_level_call_node if defined?(@top_level_call_node)

  @top_level_call_node = parse_top_level
end