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

Allow Validate macro to redefine it's output #11

Open
fnordfish opened this issue Jun 28, 2018 · 1 comment
Open

Allow Validate macro to redefine it's output #11

fnordfish opened this issue Jun 28, 2018 · 1 comment

Comments

@fnordfish
Copy link

I'm a big fan of using dry-validation contracts in TRB operations.
A cool, but too little advertised feature of a Dry::Validation::Result is it's output method, which returns only validated (and type-coerced) data. This makes it perfect for "forcing" a operation to only use safe data:

step Contract::Validate(name: :default, key: :customer)
step ->(options, params:, **) {
  params[:customer] = options["result.contract.default"].output
}

(Full Sample)

It would be great, if the Validate macro could take some option to get rid of the second step. Maybe something like the Nested macro:

step Contract::Validate(name: :default, key: :customer, output: ->(options, mutable_data:, key:, **) do
    { key => mutable_data["result.contract.default"].output }
end)
@apotonick
Copy link
Member

For further reference, this should be filed here: https://github.com/trailblazer/trailblazer-macro-contract/issues

So basically, you want to (re-)assign an attribute with an arbitrary value. This is already possible in 2.1 by using an :output filter, but it's a cool idea to add this step automatically to Validate(). 🍻

@apotonick apotonick transferred this issue from trailblazer/trailblazer Mar 7, 2019
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

No branches or pull requests

2 participants