Class: Angarium::EndpointUrlValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
app/validators/angarium/endpoint_url_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/validators/angarium/endpoint_url_validator.rb', line 3

def validate_each(record, attribute, value)
  uri = begin
    URI.parse(value.to_s)
  rescue URI::InvalidURIError
    nil
  end

  unless uri.is_a?(URI::HTTPS) && uri.host.present?
    record.errors.add(attribute, "must be a valid https URL")
    return
  end

  unless AddressPolicy.host_permitted_for_validation?(uri.host, record)
    record.errors.add(attribute, "resolves to a disallowed address")
  end
end