class DefraRuby::Validators::TokenValidator

Public Instance Methods

validate_each(record, attribute, value) click to toggle source
# File lib/defra_ruby/validators/token_validator.rb, line 8
def validate_each(record, attribute, value)
  return false unless value_is_present?(record, attribute, value)

  valid_format?(record, attribute, value)
end

Private Instance Methods

valid_format?(record, attribute, value) click to toggle source
# File lib/defra_ruby/validators/token_validator.rb, line 16
def valid_format?(record, attribute, value)
  # The token is assumed to have been generated using
  # https://github.com/robertomiranda/has_secure_token which creates
  # 24-character unique tokens
  return true if value.length == 24

  add_validation_error(record, attribute, :invalid_format)
  false
end