Class: Ast::Merge::Ruleset::Config

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

Overview

Normalized parsed merge-ruleset configuration.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source:, format:, owners:, match:, read:, attach:, path: nil, comment_style: nil, render: nil, capabilities: {}, logical_owners: {}, repair_policies: {}, surfaces: [], delegation_policies: [], directives: []) ⇒ Config

Returns a new instance of Config.



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
63
# File 'lib/ast/merge/ruleset/config.rb', line 36

def initialize(
  source:,
  format:, owners:, match:, read:, attach:, path: nil,
  comment_style: nil,
  render: nil,
  capabilities: {},
  logical_owners: {},
  repair_policies: {},
  surfaces: [],
  delegation_policies: [],
  directives: []
)
  @source = source.to_s
  @path = path
  @format = format
  @owners = owners
  @match = match
  @read = read
  @attach = attach
  @comment_style = comment_style
  @render = render
  @capabilities = capabilities.dup
  @logical_owners = logical_owners.dup
  @repair_policies = normalize_repair_policies(repair_policies)
  @surfaces = normalize_surfaces(surfaces)
  @delegation_policies = normalize_delegation_policies(delegation_policies)
  @directives = directives.dup
end

Instance Attribute Details

#attachObject (readonly)

Returns the value of attribute attach.



8
9
10
# File 'lib/ast/merge/ruleset/config.rb', line 8

def attach
  @attach
end

#capabilitiesObject (readonly)

Returns the value of attribute capabilities.



8
9
10
# File 'lib/ast/merge/ruleset/config.rb', line 8

def capabilities
  @capabilities
end

#comment_styleObject (readonly)

Returns the value of attribute comment_style.



8
9
10
# File 'lib/ast/merge/ruleset/config.rb', line 8

def comment_style
  @comment_style
end

#delegation_policiesObject (readonly)

Returns the value of attribute delegation_policies.



8
9
10
# File 'lib/ast/merge/ruleset/config.rb', line 8

def delegation_policies
  @delegation_policies
end

#directivesObject (readonly)

Returns the value of attribute directives.



8
9
10
# File 'lib/ast/merge/ruleset/config.rb', line 8

def directives
  @directives
end

#formatObject (readonly)

Returns the value of attribute format.



8
9
10
# File 'lib/ast/merge/ruleset/config.rb', line 8

def format
  @format
end

#logical_ownersObject (readonly)

Returns the value of attribute logical_owners.



8
9
10
# File 'lib/ast/merge/ruleset/config.rb', line 8

def logical_owners
  @logical_owners
end

#matchObject (readonly)

Returns the value of attribute match.



8
9
10
# File 'lib/ast/merge/ruleset/config.rb', line 8

def match
  @match
end

#ownersObject (readonly)

Returns the value of attribute owners.



8
9
10
# File 'lib/ast/merge/ruleset/config.rb', line 8

def owners
  @owners
end

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/ast/merge/ruleset/config.rb', line 8

def path
  @path
end

#readObject (readonly)

Returns the value of attribute read.



8
9
10
# File 'lib/ast/merge/ruleset/config.rb', line 8

def read
  @read
end

#renderObject (readonly)

Returns the value of attribute render.



8
9
10
# File 'lib/ast/merge/ruleset/config.rb', line 8

def render
  @render
end

#repair_policiesObject (readonly)

Returns the value of attribute repair_policies.



8
9
10
# File 'lib/ast/merge/ruleset/config.rb', line 8

def repair_policies
  @repair_policies
end

#sourceObject (readonly)

Returns the value of attribute source.



8
9
10
# File 'lib/ast/merge/ruleset/config.rb', line 8

def source
  @source
end

#surfacesObject (readonly)

Returns the value of attribute surfaces.



8
9
10
# File 'lib/ast/merge/ruleset/config.rb', line 8

def surfaces
  @surfaces
end

Class Method Details

.load(path) ⇒ Object

Raises:

  • (ArgumentError)


25
26
27
28
29
# File 'lib/ast/merge/ruleset/config.rb', line 25

def load(path)
  raise ArgumentError, "Ruleset file not found: #{path}" unless File.exist?(path)

  parse(File.read(path, encoding: 'UTF-8'), path: path)
end

.parse(source, path: nil) ⇒ Object



31
32
33
# File 'lib/ast/merge/ruleset/config.rb', line 31

def parse(source, path: nil)
  new(**Parser.parse(source, path: path))
end

Instance Method Details

#attachment_strategyObject



82
83
84
# File 'lib/ast/merge/ruleset/config.rb', line 82

def attachment_strategy
  attach
end

#feature_profile(source: :ruleset_config, capability: :full) ⇒ Object



90
91
92
# File 'lib/ast/merge/ruleset/config.rb', line 90

def feature_profile(source: :ruleset_config, capability: :full)
  RuntimeTranslator.feature_profile(self, source: source, capability: capability)
end

#runtime_declaration(source: :ruleset_config, capability: :full) ⇒ Object



86
87
88
# File 'lib/ast/merge/ruleset/config.rb', line 86

def runtime_declaration(source: :ruleset_config, capability: :full)
  RuntimeTranslator.declaration(self, source: source, capability: capability)
end

#support_style(source:, capability: :full) ⇒ Object



94
95
96
# File 'lib/ast/merge/ruleset/config.rb', line 94

def support_style(source:, capability: :full)
  RuntimeTranslator.support_style(self, source: source, capability: capability)
end

#to_hObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/ast/merge/ruleset/config.rb', line 65

def to_h
  {
    format: format,
    owners: owners,
    match: match,
    read: read,
    attach: attach,
    comment_style: comment_style,
    render: render,
    capabilities: capabilities.dup,
    logical_owners: logical_owners.dup,
    repair_policies: repair_policies.map(&:to_h),
    surfaces: surfaces.map(&:to_h),
    delegation_policies: delegation_policies.map(&:to_h)
  }.compact
end