Class: UnicodeUsernameAllowlistValidator
- Inherits:
-
Object
- Object
- UnicodeUsernameAllowlistValidator
- Defined in:
- lib/validators/unicode_username_allowlist_validator.rb
Instance Method Summary collapse
- #error_message ⇒ Object
-
#initialize(opts = {}) ⇒ UnicodeUsernameAllowlistValidator
constructor
A new instance of UnicodeUsernameAllowlistValidator.
- #valid_value?(value) ⇒ Boolean
Constructor Details
#initialize(opts = {}) ⇒ UnicodeUsernameAllowlistValidator
Returns a new instance of UnicodeUsernameAllowlistValidator.
4 5 6 |
# File 'lib/validators/unicode_username_allowlist_validator.rb', line 4 def initialize(opts = {}) @opts = opts end |
Instance Method Details
#error_message ⇒ Object
27 28 29 |
# File 'lib/validators/unicode_username_allowlist_validator.rb', line 27 def @error_message end |
#valid_value?(value) ⇒ Boolean
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/validators/unicode_username_allowlist_validator.rb', line 8 def valid_value?(value) @error_message = nil return true if value.blank? if value.match?(%r{\A/.*/[imxo]*\z}) @error_message = I18n.t("site_settings.errors.allowed_unicode_usernames.leading_trailing_slash") else begin Regexp.new(value) rescue RegexpError => e @error_message = I18n.t("site_settings.errors.allowed_unicode_usernames.regex_invalid", error: e.) end end @error_message.blank? end |