Sha256: 6e2d7840086e700e0d4d9f8100c0ba01b4462597358f9618f218a4f35cdfc6ec

Contents?: true

Size: 595 Bytes

Versions: 1

Compression:

Stored size: 595 Bytes

Contents

module Metaractor
  module ContextErrors
    def errors
      if super.nil?
        self.errors = []
      end

      super
    end

    def fail_with_error!(message:)
      add_error(message: message)
      fail!
    end

    def fail_with_errors!(messages:)
      add_errors(messages: messages)
      fail!
    end

    def add_error(message:)
      add_errors(messages: Array(message))
    end

    def add_errors(messages:)
      self.errors += messages
    end

    def error_messages
      errors.join("\n")
    end
  end
end

Interactor::Context.send(:include, Metaractor::ContextErrors)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
metaractor-1.1.0 lib/metaractor/context_errors.rb