Sha256: 94b2f8e656e17866b3392e832ce2a617072ef5c5bfc09997506ccc87738cf108
Contents?: true
Size: 954 Bytes
Versions: 3
Compression:
Stored size: 954 Bytes
Contents
# frozen_string_literal: true require 'micro/case' module Micro class Case include Micro::Attributes::Features::ActiveModelValidations def self.auto_validation_disabled? return @disable_auto_validation if defined?(@disable_auto_validation) end def self.disable_auto_validation @disable_auto_validation = true end def initialize(input) __setup_use_case(input) run_validations! if respond_to?(:run_validations!, true) end private def __call_use_case return failure_by_validation_error(self) if !self.class.auto_validation_disabled? && invalid? result = call! return result if result.is_a?(Result) raise Error::UnexpectedResult.new(self.class) end 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
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
u-case-2.6.0 | lib/micro/case/with_activemodel_validation.rb |
u-case-2.5.0 | lib/micro/case/with_activemodel_validation.rb |
u-case-2.4.0 | lib/micro/case/with_activemodel_validation.rb |