u-case 2.0.0.pre.4 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7108e24cbd9380af05232f2fa160a1131cb0fc3a717faf44a157ad577a5e1d70
4
- data.tar.gz: e2ca33aea49622868611af975e31a39d987c52401f8e3efccce0bbc1940395c6
3
+ metadata.gz: a64ec32f1fc225bd83e86b56a34eca857b1e1e220e84bd35b64b5324d3d74b60
4
+ data.tar.gz: 23d17b47d23384fba17ace8e96b22ce07f4d42f01d676e7c29c88d99e9fc2b77
5
5
  SHA512:
6
- metadata.gz: da0de298a0a3f889c13244fd60095ab6268dd35eab881aa8e10c35c3fb2c051670dc2563aef3c52e23366adba9554f31822f565c0a892fc9e0c69363f7c07c94
7
- data.tar.gz: 73b1fbaec0d6e15adb5d714491081bbf592920757b134139021ad7058e42c5eefa8ab420b7215442fcf9777ecc338cac0e4fa3b4dd8b833f4eb00fb70e1f9ab7
6
+ metadata.gz: 6b3732611a933699d9b8dfa8db011e58a317565eb7f2ab13c9f965f92f2369ac10838c99cdd1c54a977ed0e2afcf11801f8b233e62615208406da323dfab2d66
7
+ data.tar.gz: 5e967876fadc6093232c9c5d2d2a70b835cad1b7e670b61d6667cacd50ab0e5b9632ecb6fa231cb09e5f7826a26c4188911dc6fca3b3a4eb970b3eda22f1a50b
data/README.md CHANGED
@@ -34,6 +34,7 @@ The main goals of this project are:
34
34
  - [What is a strict use case?](#what-is-a-strict-use-case)
35
35
  - [Is there some feature to auto handle exceptions inside of a use case or flow?](#is-there-some-feature-to-auto-handle-exceptions-inside-of-a-use-case-or-flow)
36
36
  - [How to validate use case attributes?](#how-to-validate-use-case-attributes)
37
+ - [If I enable the auto validation, is it possible to disable it only in some specific use case classes?](#if-i-enable-the-auto-validation-is-it-possible-to-disable-it-only-in-some-specific-use-case-classes)
37
38
  - [Examples](#examples)
38
39
  - [Comparisons](#comparisons)
39
40
  - [Benchmarks](#benchmarks)
@@ -729,6 +730,31 @@ end
729
730
  # Micro::Case::Strict and Micro::Case::Safe classes will inherit this new behavior.
730
731
  ```
731
732
 
733
+ #### If I enable the auto validation, is it possible to disable it only in some specific use case classes?
734
+
735
+ Answer: Yes, it is. To do this, you only need to use the `disable_auto_validation` macro. e.g:
736
+
737
+ ```ruby
738
+ require 'u-case/with_validation'
739
+
740
+ class Multiply < Micro::Case
741
+ disable_auto_validation
742
+
743
+ attribute :a
744
+ attribute :b
745
+ validates :a, :b, presence: true, numericality: true
746
+
747
+ def call!
748
+ Success(number: a * b)
749
+ end
750
+ end
751
+
752
+ Multiply.call(a: 2, b: 'a')
753
+
754
+ # The output will be the following exception:
755
+ # TypeError (String can't be coerced into Integer)
756
+ ```
757
+
732
758
  [⬆️ Back to Top](#table-of-contents-)
733
759
 
734
760
  ### Examples
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Micro
4
4
  class Case
5
- VERSION = '2.0.0.pre.4'.freeze
5
+ VERSION = '2.0.0'.freeze
6
6
  end
7
7
  end
@@ -6,10 +6,24 @@ module Micro
6
6
  class Case
7
7
  include Micro::Attributes::Features::ActiveModelValidations
8
8
 
9
+ def self.auto_validation_disabled?
10
+ @disable_auto_validation
11
+ end
12
+
13
+ def self.disable_auto_validation
14
+ @disable_auto_validation = true
15
+ end
16
+
9
17
  def call
10
- return Failure(:validation_error) { { errors: self.errors } } unless valid?
18
+ return failure_by_validation_error(self) if !self.class.auto_validation_disabled? && invalid?
11
19
 
12
20
  __call
13
21
  end
22
+
23
+ private def failure_by_validation_error(object)
24
+ errors = object.respond_to?(:errors) ? object.errors : object
25
+
26
+ Failure(:validation_error) { { errors: errors } }
27
+ end
14
28
  end
15
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: u-case
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre.4
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Serradura
@@ -99,9 +99,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
99
  version: 2.2.0
100
100
  required_rubygems_version: !ruby/object:Gem::Requirement
101
101
  requirements:
102
- - - ">"
102
+ - - ">="
103
103
  - !ruby/object:Gem::Version
104
- version: 1.3.1
104
+ version: '0'
105
105
  requirements: []
106
106
  rubygems_version: 3.0.3
107
107
  signing_key: