Module: Ast::Merge::RSpec::CommentBehaviorMatrixAdapters

Defined in:
lib/ast/merge/rspec/comment_behavior_matrix_adapters.rb

Overview

Declarative helpers for configuring downstream CommentBehaviorMatrix adapters with only their true points of variation.

Instance Method Summary collapse

Instance Method Details

#hash_comment_line_based_comment_matrix_adapter(analysis_class:, merger_class:, structural_owners_reader:, owner_value_reader:, line_builder:, capabilities: {}, expected_literal_hash_value: '"literal # hash"', source_builder: ->(*lines) { "#{lines.join("\n")}\n" }) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ast/merge/rspec/comment_behavior_matrix_adapters.rb', line 31

def hash_comment_line_based_comment_matrix_adapter(
  analysis_class:,
  merger_class:,
  structural_owners_reader:,
  owner_value_reader:,
  line_builder:,
  capabilities: {},
  expected_literal_hash_value: '"literal # hash"',
  source_builder: ->(*lines) { "#{lines.join("\n")}\n" }
)
  line_based_comment_matrix_adapter(
    analysis_class: analysis_class,
    merger_class: merger_class,
    comment_line_builder: ->(text, indent: '') { "#{indent}# #{text}" },
    structural_owners_reader: structural_owners_reader,
    owner_value_reader: owner_value_reader,
    line_builder: line_builder,
    capabilities: capabilities,
    expected_literal_hash_value: expected_literal_hash_value,
    source_builder: source_builder
  )
end

#line_based_comment_matrix_adapter(analysis_class:, merger_class:, comment_line_builder:, structural_owners_reader:, owner_value_reader:, line_builder:, capabilities: {}, expected_literal_hash_value: '"literal # hash"', source_builder: ->(*lines) { "#{lines.join("\n")}\n" }) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ast/merge/rspec/comment_behavior_matrix_adapters.rb', line 9

def line_based_comment_matrix_adapter(
  analysis_class:,
  merger_class:,
  comment_line_builder:,
  structural_owners_reader:,
  owner_value_reader:,
  line_builder:,
  capabilities: {},
  expected_literal_hash_value: '"literal # hash"',
  source_builder: ->(*lines) { "#{lines.join("\n")}\n" }
)
  let(:comment_matrix_analysis_class) { analysis_class }
  let(:comment_matrix_merger_class) { merger_class }
  let(:comment_matrix_source_builder) { source_builder }
  let(:comment_matrix_comment_line_builder) { comment_line_builder }
  let(:comment_matrix_capabilities) { capabilities }
  let(:comment_matrix_structural_owners_reader) { structural_owners_reader }
  let(:comment_matrix_owner_value_reader) { owner_value_reader }
  let(:comment_matrix_expected_literal_hash_value) { expected_literal_hash_value }
  let(:comment_matrix_line_builder) { line_builder }
end


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/ast/merge/rspec/comment_behavior_matrix_adapters.rb', line 54

def markdown_link_definition_comment_matrix_adapter(analysis_class:, merger_class:, capabilities: {})
  line_based_comment_matrix_adapter(
    analysis_class: analysis_class,
    merger_class: merger_class,
    comment_line_builder: ->(text, indent: '') { "#{indent}<!-- #{text} -->" },
    structural_owners_reader: lambda do |analysis|
      analysis.statements.select do |statement|
        statement.respond_to?(:merge_type) && statement.merge_type == :link_definition
      end
    end,
    owner_value_reader: ->(owner) { owner.url.inspect },
    line_builder: lambda do |name, value, inline: _inline|
      "[#{name}]: #{value}"
    end,
    capabilities: {
      inline_comments: 'Markdown standalone HTML comment tracking does not attach inline comments to structural owners',
      quoted_hash_inline_literals: 'Markdown matrix adapter uses link-reference definitions without inline comment syntax',
      remove_template_missing_nodes: 'Markdown link-reference definitions are preserved even in removal mode'
    }.merge(capabilities),
    expected_literal_hash_value: '"/literal#hash"'
  )
end