Class: Canon::Rebaseliner::HeredocLocator

Inherits:
Object
  • Object
show all
Defined in:
lib/canon/rebaseliner/heredoc_locator.rb

Overview

Resolve a Prism AST node (the expected argument passed to a Canon matcher) to a HeredocTarget that can be rewritten in-place, or to a skip reason. Handles the metanorma-iso pattern of multiple sequential assignments to the same local var via "most-recent assignment before the matcher line" semantics.

Defined Under Namespace

Classes: Result

Instance Method Summary collapse

Constructor Details

#initialize(spec_path:, source:, enclosing_block:, expected_node:, matcher_line:) ⇒ HeredocLocator

Returns a new instance of HeredocLocator.

Parameters:

  • spec_path (String)

    absolute path of the spec file (passed through into any returned HeredocTarget)

  • source (String)

    full file source string

  • enclosing_block (Prism::Node)

    the it/example block node that contains the matcher invocation

  • expected_node (Prism::Node)

    the AST node passed as expected to the matcher

  • matcher_line (Integer)

    1-indexed line of the matcher call; used as the upper bound when walking backward for the most recent local-var assignment



29
30
31
32
33
34
35
36
# File 'lib/canon/rebaseliner/heredoc_locator.rb', line 29

def initialize(spec_path:, source:, enclosing_block:, expected_node:,
               matcher_line:)
  @spec_path = spec_path
  @source = source
  @enclosing_block = enclosing_block
  @expected_node = expected_node
  @matcher_line = matcher_line
end

Instance Method Details

#resolveResult

Returns :ok with a HeredocTarget, or a :skipped_* status.

Returns:

  • (Result)

    :ok with a HeredocTarget, or a :skipped_* status



39
40
41
# File 'lib/canon/rebaseliner/heredoc_locator.rb', line 39

def resolve
  resolve_node(@expected_node)
end