Class: Ast::Merge::Ruleset::FeatureProfile

Inherits:
Object
  • Object
show all
Defined in:
lib/ast/merge/ruleset/feature_profile.rb

Overview

Shared value object describing a merge implementation or ruleset surface using spec-aligned feature terminology.

FeatureProfile is the bridge from ruleset capability declarations to merge-facing behavior. It may reference parser capabilities and support styles, but it is not itself a parser adapter or renderer.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner_selector:, match_key:, read_strategy: nil, attachment_strategy: nil, comment_style: nil, render_family: nil, comment_capability: nil, support_style: nil, capabilities: {}, logical_owners: {}, repair_policies: [], surfaces: [], delegation_policies: [], metadata: {}) ⇒ FeatureProfile

Returns a new instance of FeatureProfile.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ast/merge/ruleset/feature_profile.rb', line 29

def initialize(
  owner_selector:,
  match_key:,
  read_strategy: nil,
  attachment_strategy: nil,
  comment_style: nil,
  render_family: nil,
  comment_capability: nil,
  support_style: nil,
  capabilities: {},
  logical_owners: {},
  repair_policies: [],
  surfaces: [],
  delegation_policies: [],
  metadata: {}
)
  @owner_selector = owner_selector&.to_sym
  @match_key = match_key&.to_sym
  @read_strategy = read_strategy&.to_sym
  @attachment_strategy = attachment_strategy&.to_sym
  @comment_style = comment_style&.to_sym
  @render_family = render_family&.to_sym
  @comment_capability = comment_capability
  @support_style = support_style
  @capabilities = capabilities.dup.freeze
  @logical_owners = logical_owners.dup.freeze
  @logical_owner_policies = @logical_owners.map do |kind, action|
    LogicalOwnerPolicy.new(kind: kind, action: action)
  end.freeze
  @repair_policies = normalize_repair_policies(repair_policies)
  @surfaces = normalize_surfaces(surfaces)
  @delegation_policies = normalize_delegation_policies(delegation_policies)
  @metadata = .dup.freeze
end

Instance Attribute Details

#attachment_strategyObject (readonly)

Returns the value of attribute attachment_strategy.



13
14
15
# File 'lib/ast/merge/ruleset/feature_profile.rb', line 13

def attachment_strategy
  @attachment_strategy
end

#capabilitiesObject (readonly)

Returns the value of attribute capabilities.



13
14
15
# File 'lib/ast/merge/ruleset/feature_profile.rb', line 13

def capabilities
  @capabilities
end

#comment_capabilityObject (readonly)

Returns the value of attribute comment_capability.



13
14
15
# File 'lib/ast/merge/ruleset/feature_profile.rb', line 13

def comment_capability
  @comment_capability
end

#comment_styleObject (readonly)

Returns the value of attribute comment_style.



13
14
15
# File 'lib/ast/merge/ruleset/feature_profile.rb', line 13

def comment_style
  @comment_style
end

#delegation_policiesObject (readonly)

Returns the value of attribute delegation_policies.



13
14
15
# File 'lib/ast/merge/ruleset/feature_profile.rb', line 13

def delegation_policies
  @delegation_policies
end

#logical_owner_policiesObject (readonly)

Returns the value of attribute logical_owner_policies.



13
14
15
# File 'lib/ast/merge/ruleset/feature_profile.rb', line 13

def logical_owner_policies
  @logical_owner_policies
end

#logical_ownersObject (readonly)

Returns the value of attribute logical_owners.



13
14
15
# File 'lib/ast/merge/ruleset/feature_profile.rb', line 13

def logical_owners
  @logical_owners
end

#match_keyObject (readonly)

Returns the value of attribute match_key.



13
14
15
# File 'lib/ast/merge/ruleset/feature_profile.rb', line 13

def match_key
  @match_key
end

#metadataObject (readonly)

Returns the value of attribute metadata.



13
14
15
# File 'lib/ast/merge/ruleset/feature_profile.rb', line 13

def 
  @metadata
end

#owner_selectorObject (readonly)

Returns the value of attribute owner_selector.



13
14
15
# File 'lib/ast/merge/ruleset/feature_profile.rb', line 13

def owner_selector
  @owner_selector
end

#read_strategyObject (readonly)

Returns the value of attribute read_strategy.



13
14
15
# File 'lib/ast/merge/ruleset/feature_profile.rb', line 13

def read_strategy
  @read_strategy
end

#render_familyObject (readonly)

Returns the value of attribute render_family.



13
14
15
# File 'lib/ast/merge/ruleset/feature_profile.rb', line 13

def render_family
  @render_family
end

#repair_policiesObject (readonly)

Returns the value of attribute repair_policies.



13
14
15
# File 'lib/ast/merge/ruleset/feature_profile.rb', line 13

def repair_policies
  @repair_policies
end

#support_styleObject (readonly)

Returns the value of attribute support_style.



13
14
15
# File 'lib/ast/merge/ruleset/feature_profile.rb', line 13

def support_style
  @support_style
end

#surfacesObject (readonly)

Returns the value of attribute surfaces.



13
14
15
# File 'lib/ast/merge/ruleset/feature_profile.rb', line 13

def surfaces
  @surfaces
end

Instance Method Details

#attachment_strategy_familyObject



88
89
90
# File 'lib/ast/merge/ruleset/feature_profile.rb', line 88

def attachment_strategy_family
  &.fetch(:family, nil)
end

#attachment_strategy_metadataObject



84
85
86
# File 'lib/ast/merge/ruleset/feature_profile.rb', line 84

def 
  ProfileVocabulary.(attachment_strategy)
end

#augmenter_preferred_attachment?Boolean

Returns:

  • (Boolean)


134
135
136
# File 'lib/ast/merge/ruleset/feature_profile.rb', line 134

def augmenter_preferred_attachment?
  &.fetch(:augmenter_preferred, false) || false
end

#comment_aware?Boolean

Returns:

  • (Boolean)


100
101
102
103
104
105
106
107
108
# File 'lib/ast/merge/ruleset/feature_profile.rb', line 100

def comment_aware?
  if support_style.respond_to?(:available?)
    support_style.available?
  elsif comment_capability.respond_to?(:available?)
    comment_capability.available?
  else
    false
  end
end

#delegated_surface_aware?Boolean

Returns:

  • (Boolean)


122
123
124
# File 'lib/ast/merge/ruleset/feature_profile.rb', line 122

def delegated_surface_aware?
  delegation_policies.any?
end

#layout_aware?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/ast/merge/ruleset/feature_profile.rb', line 64

def layout_aware?
  capabilities.fetch(:layout_aware, false)
end

#logical_owner?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/ast/merge/ruleset/feature_profile.rb', line 96

def logical_owner?
  capabilities.fetch(:logical_owner, logical_owners.any?)
end

#match_key_familyObject



80
81
82
# File 'lib/ast/merge/ruleset/feature_profile.rb', line 80

def match_key_family
  &.fetch(:family, nil)
end

#match_key_metadataObject



76
77
78
# File 'lib/ast/merge/ruleset/feature_profile.rb', line 76

def 
  ProfileVocabulary.(match_key)
end

#normalized_attachment?Boolean

Returns:

  • (Boolean)


130
131
132
# File 'lib/ast/merge/ruleset/feature_profile.rb', line 130

def normalized_attachment?
  &.fetch(:normalized, false) || false
end

#owner_selector_familyObject



72
73
74
# File 'lib/ast/merge/ruleset/feature_profile.rb', line 72

def owner_selector_family
  &.fetch(:family, nil)
end

#owner_selector_kindObject



92
93
94
# File 'lib/ast/merge/ruleset/feature_profile.rb', line 92

def owner_selector_kind
  OwnerSelection.selector_kind(owner_selector, logical_owners: logical_owners)
end

#owner_selector_metadataObject



68
69
70
# File 'lib/ast/merge/ruleset/feature_profile.rb', line 68

def 
  ProfileVocabulary.(owner_selector)
end

#repair_aware?Boolean

Returns:

  • (Boolean)


114
115
116
# File 'lib/ast/merge/ruleset/feature_profile.rb', line 114

def repair_aware?
  repair_policies.any?
end

#structural_only?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/ast/merge/ruleset/feature_profile.rb', line 110

def structural_only?
  !layout_aware? && !comment_aware? && !logical_owner?
end

#surface_aware?Boolean

Returns:

  • (Boolean)


118
119
120
# File 'lib/ast/merge/ruleset/feature_profile.rb', line 118

def surface_aware?
  surfaces.any?
end

#to_hObject



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/ast/merge/ruleset/feature_profile.rb', line 138

def to_h
  {
    owner_selector: owner_selector,
    match_key: match_key,
    read_strategy: read_strategy,
    attachment_strategy: attachment_strategy,
    comment_style: comment_style,
    render_family: render_family,
    comment_capability: comment_capability&.to_h,
    support_style: support_style&.to_h,
    capabilities: capabilities,
    logical_owners: logical_owners,
    logical_owner_policies: logical_owner_policies.map(&:to_h),
    repair_policies: repair_policies.map(&:to_h),
    surfaces: surfaces.map(&:to_h),
    delegation_policies: delegation_policies.map(&:to_h),
    metadata: ,
    layout_aware: layout_aware?,
    owner_selector_family: owner_selector_family,
    owner_selector_kind: owner_selector_kind,
    match_key_family: match_key_family,
    attachment_strategy_family: attachment_strategy_family,
    logical_owner: logical_owner?,
    comment_aware: comment_aware?,
    structural_only: structural_only?,
    repair_aware: repair_aware?,
    surface_aware: surface_aware?,
    delegated_surface_aware: delegated_surface_aware?,
    tracked_attachment: tracked_attachment?,
    normalized_attachment: normalized_attachment?,
    augmenter_preferred_attachment: augmenter_preferred_attachment?
  }.compact
end

#tracked_attachment?Boolean

Returns:

  • (Boolean)


126
127
128
# File 'lib/ast/merge/ruleset/feature_profile.rb', line 126

def tracked_attachment?
  &.fetch(:tracked_comments, false) || false
end