Class: Canon::Comparison::MatchOptions::JsonResolver

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

Overview

JSON-specific match options resolver

Constant Summary collapse

FORMAT_DEFAULTS =

Format defaults for JSON

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

Predefined match profiles for JSON

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

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

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

Class Method Summary collapse

Methods inherited from BaseResolver

resolve

Class Method Details

.dimension_behaviorsObject

JSON-specific dimension behaviors



80
81
82
83
84
85
86
# File 'lib/canon/comparison/match_options/json_resolver.rb', line 80

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

.format_defaults(format) ⇒ Hash

Get format-specific default options

Parameters:

  • format (Symbol)

    Format type (:json)

Returns:

  • (Hash)

    Default options for the format



61
62
63
# File 'lib/canon/comparison/match_options/json_resolver.rb', line 61

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

.get_profile_options(profile) ⇒ Hash

Get options for a named profile

Parameters:

  • profile (Symbol)

    Profile name

Returns:

  • (Hash)

    Profile options

Raises:



70
71
72
73
74
75
76
77
# File 'lib/canon/comparison/match_options/json_resolver.rb', line 70

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 JSON (collectively exhaustive)



49
50
51
52
53
54
55
# File 'lib/canon/comparison/match_options/json_resolver.rb', line 49

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