ml-archive / forms

Tools for working with Forms in Vapor
MIT License
7 stars 0 forks source link

Add ValidatorWrapper and convenience functions #12

Closed siemensikkema closed 6 years ago

siemensikkema commented 6 years ago

Allows for example:

StrongPassword()
    .transformingErrors(to: MyAppErrors.passwordTooWeak)
    .allowingNil(false)

which allows uses an existing (e.g. StrongPassword) validator but transforms the errors into something more suited to your needs and also adds a requirement that the value be non-nil.

codecov[bot] commented 6 years ago

Codecov Report

Merging #12 into master will decrease coverage by 2.79%. The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master      #12     +/-   ##
=========================================
- Coverage   76.23%   73.43%   -2.8%     
=========================================
  Files          19       21      +2     
  Lines         446      463     +17     
  Branches       22       22             
=========================================
  Hits          340      340             
- Misses        106      123     +17
Impacted Files Coverage Δ
Sources/Forms/ValidatorWrapper.swift 0% <0%> (ø)
Sources/Forms/Validation+convenience.swift 0% <0%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update fe3588e...9898a33. Read the comment docs.

siemensikkema commented 6 years ago

A possible improvement would be to add a closure instead that takes the original error and throws a new one depending on the error instead of a single error. The current functionality (as proposed in this PR) could be maintained by creating another initializer that takes an error value and calls the initializer taking a closure with a closure that just returns the given error value.