Class: RegexpListValidator
- Inherits:
-
Object
- Object
- RegexpListValidator
- Defined in:
- lib/validators/regexp_list_validator.rb
Instance Method Summary collapse
- #error_message ⇒ Object
-
#initialize(opts = {}) ⇒ RegexpListValidator
constructor
A new instance of RegexpListValidator.
- #valid_value?(value) ⇒ Boolean
Constructor Details
#initialize(opts = {}) ⇒ RegexpListValidator
Returns a new instance of RegexpListValidator.
4 5 |
# File 'lib/validators/regexp_list_validator.rb', line 4 def initialize(opts = {}) end |
Instance Method Details
#error_message ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/validators/regexp_list_validator.rb', line 21 def I18n.t( "site_settings.errors.invalid_regex_with_message", regex: @regexp, message: @error_message, ) end |
#valid_value?(value) ⇒ Boolean
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/validators/regexp_list_validator.rb', line 7 def valid_value?(value) value .split("|") .all? do |regexp| begin Regexp.new(regexp) rescue RegexpError => e @regexp = regexp @error_message = e. false end end end |