20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'app/models/concerns/shared/uri.rb', line 20
def valid_uri
return if uri_attribute.nil?
uris = URI.(uri_attribute)
if uris.count == 0
errors.add(uri_column, 'Provided URI is unparsable.')
elsif uris.count > 1 || uris[0].length != uri_attribute.length
errors.add(uri_column, 'More than a single URI present.')
else
begin
u = URI(uri_attribute)
scheme = u.scheme.upcase
unless URI.scheme_list.keys.include?(scheme)
errors.add(uri_column, "#{scheme} is not in the URI schemes list.")
end
rescue
errors.add(uri_column, "Badly formed URI #{uri_attribute} detected.")
end
end
end
|