Class: InputSanitizer::V2::Types::URLCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/input_sanitizer/v2/types.rb

Instance Method Summary collapse

Instance Method Details

#call(value, options = {}) ⇒ Object



166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/input_sanitizer/v2/types.rb', line 166

def call(value, options = {})
  if value.blank? && (options[:allow_blank] == false || options[:required] == true)
    raise InputSanitizer::BlankValueError
  elsif value == nil && options[:allow_nil] == false
    raise InputSanitizer::BlankValueError
  elsif value.blank?
    value
  else
    unless /\A#{URI.regexp(%w(http https)).to_s}\z/.match(value)
      raise InputSanitizer::TypeMismatchError.new(value, :url)
    end
    value
  end
end