Added
-
Add a Validation extension, for validating operation input with Dry Validation. (@aaronmallen and @timriley in #34, #47)
Define a contract with
params,schema, orcontract. The operation's keyword arguments are validated before the method runs, and the method receives the contract's output. If validation fails, the operation returnsFailure[:invalid, result].class CreateUser < Dry::Operation include Dry::Operation::Extensions::Validation params do required(:name).filled(:string) end def call(name:) # ... end end
By default, all keyword arguments are validated. Use
for:to validate only one keyword argument, orkeys:to validate a subset of them. All other keyword arguments are passed through untouched. Positional arguments are never validated.params(for: :attrs) do required(:name).filled(:string) end params(keys: %i[account_id scope]) do required(:account_id).filled(:string) optional(:scope).array(:string) end
-
#stepnow accepts any object that responds to#to_result, such asTry,Maybe, orValidatedfrom Dry Monads. The object is converted to a result before it is processed. (@timriley in #38)