Class: AllowedIframesValidator

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

Constant Summary collapse

VALID_ALLOWED_IFRAME_URL_REGEX =

Url starts with http:// or https:// and has at least one more additional ‘/’

%r{\Ahttps?://([^/]*/)+[^/]*\z}x

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ AllowedIframesValidator

Returns a new instance of AllowedIframesValidator.



7
8
9
# File 'lib/validators/allowed_iframes_validator.rb', line 7

def initialize(opts = {})
  @opts = opts
end

Instance Method Details

#error_messageObject



15
16
17
# File 'lib/validators/allowed_iframes_validator.rb', line 15

def error_message
  I18n.t("site_settings.errors.invalid_allowed_iframes_url")
end

#valid_value?(values) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/validators/allowed_iframes_validator.rb', line 11

def valid_value?(values)
  values.split("|").all? { _1.match? VALID_ALLOWED_IFRAME_URL_REGEX }
end