Sha256: b8e5416939a9d43af45fe866917f0fd59cd369c4320480f0027e51f55f67d0e5

Contents?: true

Size: 784 Bytes

Versions: 3

Compression:

Stored size: 784 Bytes

Contents

# frozen_string_literal: true

require 'trailblazer/operation/persist'

module Pragma
  module Macro
    module Contract
      def self.Persist(method: :save, name: 'default')
        step = lambda do |input, options|
          Trailblazer::Operation::Pipetree::Step.new(
            Trailblazer::Operation::Contract::Persist(method: method, name: name).first
          ).call(input, options).tap do |result|
            unless result
              options['result.response'] = Pragma::Operation::Response::UnprocessableEntity.new(
                errors: options["contract.#{name}"].model.errors.messages
              ).decorate_with(Pragma::Decorator::Error)
            end
          end
        end

        [step, name: "contract.#{name}.#{method}"]
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pragma-2.4.0 lib/pragma/macro/contract/persist.rb
pragma-2.3.0 lib/pragma/macro/contract/persist.rb
pragma-2.2.0 lib/pragma/macro/contract/persist.rb