so I've been playing with composable validations

the cool part here is that it is easy to combine validations for various use cases. here's an example for "Change password" where you keep the same password if you don't fill in any password:

(syntax may be subject to change)

and it's easy to refactor and support multiple use cases. maybe you have a page where you *must* change the password. ta-da:

ChangePassword = form(…) | match_with { }
MaybeChangePassword = continue_if { … } | ChangePassword

and maybe you have multiple forms on one page? well, it trivially supports both nested:

form(user_info: form(…), account_info: form(…))

and merged:

form(…) & form(…)

and nothing is form specific either. you can validate a single string if you want:

(trim | required | integer).validate(" 123 ").value # => 123

@judofyr This looks fantastic! It has a big FP feel to it. The fun parts, not the weird parts. :-)

@jgaskins it's beginning to fall into place now. this is based on ideas I've had floating around in various projects for years.

@art_codesmith thanks. quite a lot of docs required, but it's starting to take shape now. I'm aiming for a release (or semi-release) before Oct 25

@art_codesmith feel free to try it out:

gem 'ippon', github: 'judofyr/ippon', branch: 'composable-validate'

I would love some feedback :)

@judofyr looks pretty nice. I like this API better than dry-validation.

Sign in to participate in the conversation

A Mastodon instance for Rubyists & friends