Class: Canon::Comparison::MatchOptions::BaseResolver

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

Overview

Base class for match option resolvers Provides common resolve logic with format-specific customization

Direct Known Subclasses

JsonResolver, XmlResolver, YamlResolver

Class Method Summary collapse

Class Method Details

.format_defaults(format) ⇒ Hash

Get format-specific default options Subclasses should override this

Parameters:

  • format (Symbol)

    Format type

Returns:

  • (Hash)

    Default options for the format

Raises:

  • (NotImplementedError)


71
72
73
74
# File 'lib/canon/comparison/match_options/base_resolver.rb', line 71

def format_defaults(format)
  raise NotImplementedError,
        "#{self.class} must implement #format_defaults"
end

.get_profile_options(profile) ⇒ Hash

Get options for a named profile Subclasses should override this

Parameters:

  • profile (Symbol)

    Profile name

Returns:

  • (Hash)

    Profile options

Raises:



82
83
84
85
# File 'lib/canon/comparison/match_options/base_resolver.rb', line 82

def get_profile_options(profile)
  raise NotImplementedError,
        "#{self.class} must implement #get_profile_options"
end

.match_dimensionsArray<Symbol>

Get valid match dimensions for this format Subclasses should override this

Returns:

  • (Array<Symbol>)

    Valid dimensions

Raises:

  • (NotImplementedError)


91
92
93
94
# File 'lib/canon/comparison/match_options/base_resolver.rb', line 91

def match_dimensions
  raise NotImplementedError,
        "#{self.class} must implement #match_dimensions"
end

.resolve(format:, match_profile: nil, match: nil, preprocessing: nil, global_profile: nil, global_options: nil) ⇒ Hash

Resolve match options with precedence handling

Precedence order (highest to lowest):

  1. Explicit match parameter

  2. Profile from match_profile parameter

  3. Global configuration

  4. Format-specific defaults

Parameters:

  • format (Symbol)

    Format type

  • match_profile (Symbol, nil) (defaults to: nil)

    Profile name

  • match (Hash, nil) (defaults to: nil)

    Explicit options per dimension

  • preprocessing (Symbol, nil) (defaults to: nil)

    Preprocessing option

  • global_profile (Symbol, nil) (defaults to: nil)

    Global configured profile

  • global_options (Hash, nil) (defaults to: nil)

    Global configured options

Returns:

  • (Hash)

    Resolved options for all dimensions



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/canon/comparison/match_options/base_resolver.rb', line 25

def resolve(format:, match_profile: nil, match: nil, preprocessing: nil,
            global_profile: nil, global_options: nil)
  # Start with format-specific defaults
  options = format_defaults(format).dup

  # Store format for later use (e.g., WhitespaceSensitivity needs it)
  options[:format] = format

  # Apply global profile if specified
  if global_profile
    profile_opts = get_profile_options(global_profile)
    options.merge!(profile_opts)
  end

  # Apply global options if specified
  if global_options
    validate_match_options!(global_options)
    options.merge!(global_options)
  end

  # Apply per-call profile if specified (overrides global)
  if match_profile
    profile_opts = get_profile_options(match_profile)
    options.merge!(profile_opts)
  end

  # Apply per-call preprocessing if specified (overrides profile)
  if preprocessing
    validate_preprocessing!(preprocessing)
    options[:preprocessing] = preprocessing
  end

  # Apply per-call explicit options if specified (highest priority)
  if match
    validate_match_options!(match)
    options.merge!(match)
  end

  options
end