gems dry-operation 1.2.0
v1.2.0

30 minutes ago

Added

  • Add a Validation extension, for validating operation input with Dry Validation. (@aaronmallen and @timriley in #34, #47)

    Define a contract with params, schema, or contract. The operation's keyword arguments are validated before the method runs, and the method receives the contract's output. If validation fails, the operation returns Failure[: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, or keys: 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
  • #step now accepts any object that responds to #to_result, such as Try, Maybe, or Validated from Dry Monads. The object is converted to a result before it is processed. (@timriley in #38)

Changed

  • Require dry-monads 1.10 or later. This makes sure that dry-monads' RSpec extension is available for testing your operations. (@timriley in #45)
  • Require Ruby 3.3 or later. (@timriley)

Compare v1.1.0 ... v1.2.0

Don't miss a new dry-operation release

NewReleases is sending notifications on new releases.