class Shoulda::Matchers::ActiveModel::ValidateConfirmationOfMatcher

@private

def allows_different_value

def allows_different_value
  allows_value_of('different value') do |matcher|
    qualify_matcher(matcher, 'some value')
  end
end

def allows_missing_confirmation

def allows_missing_confirmation
  allows_value_of('any value') do |matcher|
    qualify_matcher(matcher, nil)
  end
end

def allows_same_value

def allows_same_value
  allows_value_of('same value') do |matcher|
    qualify_matcher(matcher, 'same value')
  end
end

def disallows_different_value

def disallows_different_value
  disallows_value_of('different value') do |matcher|
    qualify_matcher(matcher, 'some value')
  end
end

def disallows_missing_confirmation

def disallows_missing_confirmation
  disallows_value_of('any value') do |matcher|
    qualify_matcher(matcher, nil)
  end
end

def disallows_same_value

def disallows_same_value
  disallows_value_of('same value') do |matcher|
    qualify_matcher(matcher, 'same value')
  end
end

def does_not_match?(subject)

def does_not_match?(subject)
  super(subject)
  allows_different_value ||
    disallows_same_value ||
    disallows_missing_confirmation
end

def initialize(attribute)

def initialize(attribute)
  super
  @expected_message = :confirmation
  @confirmation_attribute = "#{attribute}_confirmation"
end

def matches?(subject)

def matches?(subject)
  super(subject)
  disallows_different_value &&
    allows_same_value &&
    allows_missing_confirmation
end

def qualify_matcher(matcher, confirmation_attribute_value)

def qualify_matcher(matcher, confirmation_attribute_value)
  matcher.values_to_preset = {
    confirmation_attribute => confirmation_attribute_value,
  }
  matcher.with_message(
    @expected_message,
    against: confirmation_attribute,
    values: { attribute: attribute },
  )
end

def simple_description

def simple_description
  "validate that :#{@confirmation_attribute} matches :#{@attribute}"
end