Class: RegexpListValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/validators/regexp_list_validator.rb

Instance Method Summary collapse

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_messageObject



21
22
23
24
25
26
27
# File 'lib/validators/regexp_list_validator.rb', line 21

def error_message
  I18n.t(
    "site_settings.errors.invalid_regex_with_message",
    regex: @regexp,
    message: @error_message,
  )
end

#valid_value?(value) ⇒ Boolean

Returns:

  • (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.message
        false
      end
    end
end