Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for coercing valid URLs #2

Merged
merged 2 commits into from Apr 14, 2014
Merged

Add support for coercing valid URLs #2

merged 2 commits into from Apr 14, 2014

Conversation

jcf
Copy link

@jcf jcf commented Apr 14, 2014

This makes it possible to coerce a URL string into a java.net.URL.

The decision to use a URL as opposed to a URI comes from the fact we want to ensure there is a protocol in the URL string.

We can add support for both via uri and url functions if anyone is interested in the differences between the underlying classes we coerce to.

@weavejester
Copy link

We probably want to do this via a coercion, i.e. something like:

(defn string->url [_ value]
  (if (valid? schemes value)
    {:value (URL. value)}
    {:errors #{(invalid-url schemes value)}})))

(def url-coercions
  {[String URL] string->url})

This will allow the writing of rules like:

{:website URL}

That are independent of input. In the case of JSON we'd accept a string, but with edn we might have something more sophisticated.

@jcf
Copy link
Author

jcf commented Apr 14, 2014

That's very nice! We should advertise this functionality in the constraint wiki.

jcf pushed a commit that referenced this pull request Apr 14, 2014
Add support for coercing valid URLs
@jcf jcf merged commit 9997ef2 into master Apr 14, 2014
@jcf jcf deleted the coerce-urls branch April 14, 2014 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants