Class: Ast::Merge::Comment::SupportStyle

Inherits:
Object
  • Object
show all
Defined in:
lib/ast/merge/comment/support_style.rb

Overview

Describes how a merge pipeline will own, read, and write comments.

Capability answers what a parser/backend can provide. SupportStyle answers how the merge implementation intends to use those comments end-to-end. Keeping the two concepts separate lets parsers expose native comment information while merge gems still converge on a portable write contract, even when the real architecture uses a synthetic ownership or output pipeline internally.

This is the support-style/write-model axis. It is deliberately separate from parser capability and from ruleset capability declarations.

Constant Summary collapse

STYLES =
%i[
  source_augmented_portable_write
  native_read_portable_write
  native_mutation
  hybrid_native_owned
  unavailable
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(style:, details: {}, **options) ⇒ void

Parameters:

  • style (Symbol)

    normalized support style name

  • details (Hash) (defaults to: {})

    base metadata

  • options (Hash)

    additional metadata merged into details



78
79
80
81
# File 'lib/ast/merge/comment/support_style.rb', line 78

def initialize(style:, details: {}, **options)
  @style = normalize_style(style)
  @details = details.merge(options).freeze
end

Instance Attribute Details

#detailsObject (readonly)

Returns the value of attribute details.



26
27
28
# File 'lib/ast/merge/comment/support_style.rb', line 26

def details
  @details
end

#styleObject (readonly)

Returns the value of attribute style.



26
27
28
# File 'lib/ast/merge/comment/support_style.rb', line 26

def style
  @style
end

Class Method Details

.hybrid_native_owned(**details) ⇒ SupportStyle

Build a support style that mixes native-owned and synthetic comment output. This should remain an escape hatch, not the default target.

Parameters:

  • details (Hash)

    producer metadata

Returns:



61
62
63
# File 'lib/ast/merge/comment/support_style.rb', line 61

def hybrid_native_owned(**details)
  new(style: :hybrid_native_owned, details: details)
end

.native_mutation(**details) ⇒ SupportStyle

Build a support style that mutates and emits comments via the native parser AST.

Parameters:

  • details (Hash)

    producer metadata

Returns:



52
53
54
# File 'lib/ast/merge/comment/support_style.rb', line 52

def native_mutation(**details)
  new(style: :native_mutation, details: details)
end

.native_read_portable_write(**details) ⇒ SupportStyle

Build a support style that reads parser-native comments but emits them through the merge layer's portable write contract.

Parameters:

  • details (Hash)

    producer metadata

Returns:



43
44
45
# File 'lib/ast/merge/comment/support_style.rb', line 43

def native_read_portable_write(**details)
  new(style: :native_read_portable_write, details: details)
end

.source_augmented_portable_write(**details) ⇒ SupportStyle

Build a support style that scans or tracks comments from source and emits them entirely through the merge layer.

Parameters:

  • details (Hash)

    producer metadata

Returns:



34
35
36
# File 'lib/ast/merge/comment/support_style.rb', line 34

def source_augmented_portable_write(**details)
  new(style: :source_augmented_portable_write, details: details)
end

.unavailable(**details) ⇒ SupportStyle

Build a support style describing no usable comment pipeline.

Parameters:

  • details (Hash)

    producer metadata

Returns:



69
70
71
# File 'lib/ast/merge/comment/support_style.rb', line 69

def unavailable(**details)
  new(style: :unavailable, details: details)
end

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


115
116
117
# File 'lib/ast/merge/comment/support_style.rb', line 115

def available?
  !unavailable?
end

#hybrid_native_owned?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/ast/merge/comment/support_style.rb', line 95

def hybrid_native_owned?
  style == :hybrid_native_owned
end

#inspectString

Return a concise debug representation of the support style.

Returns:

  • (String)


136
137
138
# File 'lib/ast/merge/comment/support_style.rb', line 136

def inspect
  "#<#{self.class.name} style=#{style} details=#{details.inspect}>"
end

#native_mutation?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/ast/merge/comment/support_style.rb', line 91

def native_mutation?
  style == :native_mutation
end

#native_read?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/ast/merge/comment/support_style.rb', line 107

def native_read?
  native_read_portable_write? || native_mutation? || hybrid_native_owned?
end

#native_read_portable_write?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/ast/merge/comment/support_style.rb', line 87

def native_read_portable_write?
  style == :native_read_portable_write
end

#native_write?Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/ast/merge/comment/support_style.rb', line 111

def native_write?
  native_mutation? || hybrid_native_owned?
end

#portable_write?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/ast/merge/comment/support_style.rb', line 103

def portable_write?
  source_augmented_portable_write? || native_read_portable_write?
end

#source_augmented_portable_write?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/ast/merge/comment/support_style.rb', line 83

def source_augmented_portable_write?
  style == :source_augmented_portable_write
end

#to_hHash

Return the support style as a normalized Hash.

Returns:

  • (Hash)


122
123
124
125
126
127
128
129
130
131
# File 'lib/ast/merge/comment/support_style.rb', line 122

def to_h
  {
    style: style,
    details: details,
    portable_write: portable_write?,
    native_read: native_read?,
    native_write: native_write?,
    available: available?
  }
end

#unavailable?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/ast/merge/comment/support_style.rb', line 99

def unavailable?
  style == :unavailable
end