avram
avram copied to clipboard
Add validator for URLs
Would be awesome to have a built-in validator for handling URLs. I think to start, it would just run through URI.parse, and then validate that it has a valid scheme, and hostname.
This can obviously get a bit tricky since doing relative ftp URLs like ftp:///upload could be "valid", but I think it's pretty common to store a standard HTTP url, and having a nice method to validate those would be great.
Maybe something that looks like this?
def validates_url_format(
attribute : Avram::Attribute,
scheme : String = "https",
relative : Bool = false,
message : String = "must be a URL"
)
end