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: {
    preprocessing: :none,
    text_content: :strict,
    structural_whitespace: :strict,
    key_order: :strict,
  },

  spec_friendly: {
    preprocessing: :normalize,
    text_content: :strict,
    structural_whitespace: :ignore,
    key_order: :ignore,
  },

  content_only: {
    preprocessing: :normalize,
    text_content: :normalize,
    structural_whitespace: :ignore,
    key_order: :ignore,
  },
}.freeze

Class Method Summary collapse

Methods inherited from BaseResolver

match_dimensions, resolve

Class Method Details

.format_defaults(format) ⇒ Object

Get format-specific default options



44
45
46
# File 'lib/canon/comparison/match_options/json_resolver.rb', line 44

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

.get_profile_options(profile) ⇒ Object

Get options for a named profile



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

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