Module: Psych::Merge

Defined in:
lib/psych/merge.rb,
lib/psych/merge/version.rb

Defined Under Namespace

Modules: Version

Constant Summary collapse

PACKAGE_NAME =
"psych-merge"
BACKEND_REFERENCE =
TreeHaver::BackendReference.new(id: "psych", family: "native").freeze
VERSION =
Version::VERSION

Class Method Summary collapse

Class Method Details

.available_yaml_backendsObject



19
20
21
# File 'lib/psych/merge.rb', line 19

def available_yaml_backends
  [BACKEND_REFERENCE]
end

.match_yaml_owners(template, destination) ⇒ Object



58
59
60
# File 'lib/psych/merge.rb', line 58

def match_yaml_owners(template, destination)
  Yaml::Merge.match_yaml_owners(template, destination)
end

.merge_yaml(template_source, destination_source, dialect, backend: nil) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/psych/merge.rb', line 62

def merge_yaml(template_source, destination_source, dialect, backend: nil)
  requested = backend.to_s.empty? ? BACKEND_REFERENCE.id : backend.to_s
  return unsupported_feature_merge_result("Unsupported YAML backend #{requested}.") unless requested == BACKEND_REFERENCE.id

  Yaml::Merge.merge_yaml_with_parser(template_source, destination_source, dialect) do |source, parse_dialect|
    parse_yaml(source, parse_dialect, backend: requested)
  end
end

.parse_yaml(source, dialect, backend: nil) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/psych/merge.rb', line 47

def parse_yaml(source, dialect, backend: nil)
  requested = backend.to_s.empty? ? BACKEND_REFERENCE.id : backend.to_s
  return unsupported_feature_parse_result("Unsupported YAML backend #{requested}.") unless requested == BACKEND_REFERENCE.id
  return unsupported_feature_parse_result("Unsupported YAML dialect #{dialect}.") unless dialect == "yaml"

  parsed = YAML.safe_load(source, permitted_classes: [], aliases: false)
  Yaml::Merge.analyze_yaml_document(parsed, dialect)
rescue StandardError => e
  parse_error_result(e.message)
end

.yaml_backend_feature_profile(backend: nil) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/psych/merge.rb', line 23

def yaml_backend_feature_profile(backend: nil)
  requested = backend.to_s.empty? ? BACKEND_REFERENCE.id : backend.to_s
  return unsupported_feature_result("Unsupported YAML backend #{requested}.") unless requested == BACKEND_REFERENCE.id

  yaml_feature_profile.merge(
    backend: BACKEND_REFERENCE.id,
    backend_ref: BACKEND_REFERENCE.to_h
  )
end

.yaml_feature_profileObject



15
16
17
# File 'lib/psych/merge.rb', line 15

def yaml_feature_profile
  Yaml::Merge.yaml_feature_profile
end

.yaml_plan_context(backend: nil) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/psych/merge.rb', line 33

def yaml_plan_context(backend: nil)
  profile = yaml_backend_feature_profile(backend: backend)
  return profile if profile[:ok] == false

  {
    family_profile: yaml_feature_profile,
    feature_profile: {
      backend: profile[:backend],
      supports_dialects: true,
      supported_policies: profile[:supported_policies]
    }
  }
end