dry-rb / dry-logic

Predicate logic with rule composition
https://dry-rb.org/gems/dry-logic/
MIT License
179 stars 66 forks source link

Add URI predicate #71

Closed nerburish closed 4 years ago

nerburish commented 4 years ago

Hi all, I was looking for create a custom predicate to check a valid URI format.

Looking for it, I noticed that this case maybe its similar to the request of add the uuid predicate: https://github.com/dry-rb/dry-logic/issues/53

Then, I followed the same pattern to add this for the URI format.

Greetings

solnic commented 4 years ago

Thank you! I guess we could also add a shortcut for the common case of checking an HTTP URI, something like http_uri?(input) that simply delegates to uri?(["http", "https"], input) 🤔

nerburish commented 4 years ago

Yes, I agree! Something like http_uri? or url? would be more typical use and would be nice as predciate itself.

In fact, at first time I was thinking about to restrict it, but then I thought that there are some cases like mailto or tel where you need to be more flexible .

Btw, it's possible to have a predicate with default params? When I tried to to use it as (uri?) it always throw an error claiming for a param.

Greetings

solnic commented 4 years ago

@nerburish right,url? makes more sense as the name :)

Btw, it's possible to have a predicate with default params?

it's not, because input is passed as the last argument, so it's either args + input or just input, you can't have optional args and input at the same time.