Class: Canon::Comparison::MatchOptions::YamlResolver

Inherits:
BaseResolver
  • Object
show all
Defined in:
lib/canon/comparison/match_options/yaml_resolver.rb

Overview

YAML-specific match options resolver

Constant Summary collapse

FORMAT_DEFAULTS =

Format defaults for YAML

{
  yaml: {
    preprocessing: :none,
    text_content: :strict,
    structural_whitespace: :ignore,
    key_order: :ignore,
    comments: :ignore,
  },
}.freeze
MATCH_PROFILES =

Predefined match profiles for YAML

{
  # Strict: Match exactly
  strict: {
    preprocessing: :none,
    text_content: :strict,
    structural_whitespace: :strict,
    key_order: :strict,
    comments: :strict,
  },

  # Spec-friendly: Formatting and order don't matter
  spec_friendly: {
    preprocessing: :normalize,
    text_content: :strict,
    structural_whitespace: :ignore,
    key_order: :ignore,
    comments: :ignore,
  },

  # Content-only: Only values matter
  content_only: {
    preprocessing: :normalize,
    text_content: :normalize,
    structural_whitespace: :ignore,
    key_order: :ignore,
    comments: :ignore,
  },
}.freeze

Class Method Summary collapse

Methods inherited from BaseResolver

resolve

Class Method Details

.dimension_behaviorsObject

YAML-specific dimension behaviors



85
86
87
88
89
90
91
92
# File 'lib/canon/comparison/match_options/yaml_resolver.rb', line 85

def dimension_behaviors
  {
    text_content: %i[strict normalize ignore].freeze,
    structural_whitespace: %i[strict normalize ignore].freeze,
    key_order: %i[strict ignore].freeze,
    comments: %i[strict ignore].freeze,
  }
end

.format_defaults(format) ⇒ Hash

Get format-specific default options

Parameters:

  • format (Symbol)

    Format type (:yaml)

Returns:

  • (Hash)

    Default options for the format



66
67
68
# File 'lib/canon/comparison/match_options/yaml_resolver.rb', line 66

def format_defaults(format)
  FORMAT_DEFAULTS[format]&.dup || FORMAT_DEFAULTS[:yaml].dup
end

.get_profile_options(profile) ⇒ Hash

Get options for a named profile

Parameters:

  • profile (Symbol)

    Profile name

Returns:

  • (Hash)

    Profile options

Raises:



75
76
77
78
79
80
81
82
# File 'lib/canon/comparison/match_options/yaml_resolver.rb', line 75

def get_profile_options(profile)
  unless MATCH_PROFILES.key?(profile)
    raise Canon::Error,
          "Unknown match profile: #{profile}. " \
          "Valid profiles: #{MATCH_PROFILES.keys.join(', ')}"
  end
  MATCH_PROFILES[profile].dup
end

.match_dimensionsObject

Matching dimensions for YAML (collectively exhaustive)



53
54
55
56
57
58
59
60
# File 'lib/canon/comparison/match_options/yaml_resolver.rb', line 53

def match_dimensions
  %i[
    text_content
    structural_whitespace
    key_order
    comments
  ].freeze
end