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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5e5c6268a2647377005c88680b1683d03d5c7f59fa4684b1cd95206d02909d8b
4
- data.tar.gz: a38eaad51255f7102530cf35e3eb746bdd70619bfdfb733e7078c3cfd4af2f8d
3
+ metadata.gz: 27572593039a15f485fce6357932e309b53b7b9cfd2ae7020b4fdc2d0ede36e2
4
+ data.tar.gz: 813b56a84c4995231a683538d95617e7a21c77a68ae69ecd5ea550dbf2d3810d
5
5
  SHA512:
6
- metadata.gz: 4a2e24f10f67a9ac9bf9dfb834dbd0b0d28743d4d43d73e6867b58db6f30e0907e76d9b8b5155efa8c502268a0696a23bbdc3cc54572a144af081d6dd4f24015
7
- data.tar.gz: a5433c27e43e96e1956d4f42e5418477734d0f6d095619d5e380a12bb4292ba16267b012be1c1da3755b7e6bcb10be57d679d3280cbd0b6862433ef33df97de3
6
+ metadata.gz: 11d378f2bb03173b9f6ca13963e885d12b8ff6ca29734ce988fde17511d8fe3305338cfc3855b39414b726fb7d0b25ea2ad24e4b0a9030b40bab59539be37f97
7
+ data.tar.gz: e6de73062645d94b1dd5ba24ef67b80dc44449f44844454761321841d59eed2efe80ad76c62e210a0f8bdddbc32b9cff8d32c40ef44e2853c2cfd60e6dfba2e7
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.10.0] - 2026-11-19
4
+ - See root CHANGELOG.md for details.
5
+
3
6
  ## [2.9.0] - 2026-11-12
4
7
  - See root CHANGELOG.md for details.
5
8
 
@@ -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, error_message(:not_removed)
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)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Yes
4
4
  module Core
5
- VERSION = '2.9.0'
5
+ VERSION = '2.10.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yes-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.9.0
4
+ version: 2.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nico Ritsche