Module: Ast::Merge::YamlDocument
- Defined in:
- lib/ast/merge/yaml_document.rb
Overview
Parser-neutral semantic analysis shared by YAML backend providers. rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/ModuleLength, Metrics/PerceivedComplexity -- recursive YAML validation, rendering, and ownership are one parser-neutral semantic boundary
Class Method Summary collapse
Class Method Details
.analyze(parsed, dialect) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ast/merge/yaml_document.rb', line 12 def analyze(parsed, dialect) return unsupported("Unsupported YAML dialect #{dialect}.") unless dialect == 'yaml' return parse_error('YAML documents must parse to a mapping root.') unless parsed.is_a?(Hash) validated = validate_node(parsed, '') return { ok: false, diagnostics: [validated[:diagnostic]], policies: [] } unless validated[:ok] { ok: true, diagnostics: [], analysis: { kind: 'yaml', dialect: 'yaml', normalized_source: canonical_yaml(validated[:value]), document: validated[:value], root_kind: 'mapping', owners: collect_owners(validated[:value]) }, policies: [] } end |
.match_owners(template, destination) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ast/merge/yaml_document.rb', line 34 def match_owners(template, destination) destination_paths = destination[:owners].to_h { |owner| [owner[:path], true] } template_paths = template[:owners].to_h { |owner| [owner[:path], true] } { matched: template[:owners] .filter { |owner| destination_paths[owner[:path]] } .map { |owner| { template_path: owner[:path], destination_path: owner[:path] } }, unmatched_template: template[:owners].map { |owner| owner[:path] }.reject { |path| destination_paths[path] }, unmatched_destination: destination[:owners] .map { |owner| owner[:path] } .reject { |path| template_paths[path] } } end |