Sha256: 14a9f5e55a3f5d61b70901728c6ed7ab00954d4e33e488fe45dec931164a3982

Contents?: true

Size: 638 Bytes

Versions: 1

Compression:

Stored size: 638 Bytes

Contents

# frozen_string_literal: true

require 'micro/case'

module Micro
  class Case
    include Micro::Attributes::Features::ActiveModelValidations

    def self.auto_validation_disabled?
      @disable_auto_validation
    end

    def self.disable_auto_validation
      @disable_auto_validation = true
    end

    def call
      return failure_by_validation_error(self) if !self.class.auto_validation_disabled? && invalid?

      __call
    end

    private def failure_by_validation_error(object)
      errors = object.respond_to?(:errors) ? object.errors : object

      Failure(:validation_error) { { errors: errors } }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
u-case-2.0.0 lib/micro/case/with_validation.rb