yes-core 2.9.0 → 2.10.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 +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/yes/core/command_handling/guard_evaluator.rb +23 -2
- data/lib/yes/core/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 27572593039a15f485fce6357932e309b53b7b9cfd2ae7020b4fdc2d0ede36e2
|
|
4
|
+
data.tar.gz: 813b56a84c4995231a683538d95617e7a21c77a68ae69ecd5ea550dbf2d3810d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 11d378f2bb03173b9f6ca13963e885d12b8ff6ca29734ce988fde17511d8fe3305338cfc3855b39414b726fb7d0b25ea2ad24e4b0a9030b40bab59539be37f97
|
|
7
|
+
data.tar.gz: e6de73062645d94b1dd5ba24ef67b80dc44449f44844454761321841d59eed2efe80ad76c62e210a0f8bdddbc32b9cff8d32c40ef44e2853c2cfd60e6dfba2e7
|
data/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,12 @@ module Yes
|
|
|
9
9
|
class InvalidTransition < TransitionError; end
|
|
10
10
|
class NoChangeTransition < TransitionError; end
|
|
11
11
|
|
|
12
|
+
# Key under which the failed guard's name is put into the error's extra, so that clients
|
|
13
|
+
# can tell guards apart independent of the (translated) error message.
|
|
14
|
+
ERROR_CODE_KEY = :code
|
|
15
|
+
# Key under which a non-Hash error extra is kept once the code is added next to it.
|
|
16
|
+
ERROR_VALUE_KEY = :value
|
|
17
|
+
|
|
12
18
|
class << self
|
|
13
19
|
# @return [Hash<Symbol, Proc>] Hash of registered guards with names as keys and blocks as values
|
|
14
20
|
def guards
|
|
@@ -84,7 +90,7 @@ module Yes
|
|
|
84
90
|
|
|
85
91
|
return if aggregate.public_send(config[:attr_name]).blank?
|
|
86
92
|
|
|
87
|
-
raise InvalidTransition,
|
|
93
|
+
raise InvalidTransition.new(error_message(:not_removed), extra: extra_with_code(nil, :not_removed))
|
|
88
94
|
end
|
|
89
95
|
|
|
90
96
|
# Evaluates a single guard and raises appropriate error if it fails
|
|
@@ -102,7 +108,22 @@ module Yes
|
|
|
102
108
|
extra = error_extra.respond_to?(:call) ? evaluate_with_locale(&error_extra) : error_extra
|
|
103
109
|
|
|
104
110
|
error_class = name == :no_change ? NoChangeTransition : InvalidTransition
|
|
105
|
-
raise error_class.new(error_message(name), extra:)
|
|
111
|
+
raise error_class.new(error_message(name), extra: extra_with_code(extra, name))
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# Adds the name of the failed guard to the error extra under {ERROR_CODE_KEY}.
|
|
115
|
+
#
|
|
116
|
+
# A Hash extra keeps its entries (the guard name wins over an entry with the same key), any
|
|
117
|
+
# other non-blank extra is kept under {ERROR_VALUE_KEY}.
|
|
118
|
+
#
|
|
119
|
+
# @param extra [Hash, Object, nil] The extra given by the guard definition
|
|
120
|
+
# @param guard_name [Symbol] The name of the failed guard
|
|
121
|
+
# @return [Hash] The extra including the guard name as a String
|
|
122
|
+
def extra_with_code(extra, guard_name)
|
|
123
|
+
code = { ERROR_CODE_KEY => guard_name.to_s }
|
|
124
|
+
return code if extra.blank?
|
|
125
|
+
|
|
126
|
+
(extra.is_a?(Hash) ? extra : { ERROR_VALUE_KEY => extra }).merge(code)
|
|
106
127
|
end
|
|
107
128
|
|
|
108
129
|
def value_changed?(val1, val2)
|
data/lib/yes/core/version.rb
CHANGED