cmdx 1.7.3 → 1.7.4
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 +5 -1
- data/lib/cmdx/errors.rb +25 -3
- data/lib/cmdx/result.rb +1 -1
- data/lib/cmdx/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: ff39f948f58871f530cfe7c94fc3b2ced9fe4cd9454147c7f9c5a68419e05488
|
4
|
+
data.tar.gz: fe3771fdcdaf0caff34f24c96ff424d4a0452d34072b05f3e9dc773301e64a3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2948e478871aefd1f966dd3c6ff37adbb4c2bdeb7797d926d1b70de067ed1b3fedc7a8a5ac76c3d69cdac72d9ff038ac3e47bb2c676cead50ec3108ae4f9c38
|
7
|
+
data.tar.gz: 20b3808d5cca7c389a9d29396441475cb17a2b0e93c3e4b7ceb2132bf781521d5ff1b5a90487bced9a3b402e5acfc88f714fc94f14ef5b9edf9f801d8c482f89
|
data/CHANGELOG.md
CHANGED
@@ -4,7 +4,11 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
-
## [
|
7
|
+
## [1.7.4] - 2025-09-03
|
8
|
+
|
9
|
+
### Added
|
10
|
+
- Added errors delegation from result object
|
11
|
+
- Added `full_messages` and `to_hash` methods to errors
|
8
12
|
|
9
13
|
## [1.7.3] - 2025-09-03
|
10
14
|
|
data/lib/cmdx/errors.rb
CHANGED
@@ -48,6 +48,18 @@ module CMDx
|
|
48
48
|
!messages[attribute].empty?
|
49
49
|
end
|
50
50
|
|
51
|
+
# Convert errors to a hash format with arrays of fullmessages.
|
52
|
+
#
|
53
|
+
# @return [Hash{Symbol => Array<String>}] Hash with attribute keys and message arrays
|
54
|
+
#
|
55
|
+
# @example
|
56
|
+
# errors.full_messages # => { email: ["email must be valid format", "email cannot be blank"] }
|
57
|
+
def full_messages
|
58
|
+
messages.each_with_object({}) do |(attribute, messages), hash|
|
59
|
+
hash[attribute] = messages.map { |message| "#{attribute} #{message}" }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
51
63
|
# Convert errors to a hash format with arrays of messages.
|
52
64
|
#
|
53
65
|
# @return [Hash{Symbol => Array<String>}] Hash with attribute keys and message arrays
|
@@ -58,6 +70,18 @@ module CMDx
|
|
58
70
|
messages.transform_values(&:to_a)
|
59
71
|
end
|
60
72
|
|
73
|
+
# Convert errors to a hash format with optional full messages.
|
74
|
+
#
|
75
|
+
# @param full [Boolean] Whether to include full messages with attribute names
|
76
|
+
# @return [Hash{Symbol => Array<String>}] Hash with attribute keys and message arrays
|
77
|
+
#
|
78
|
+
# @example
|
79
|
+
# errors.to_hash # => { email: ["must be valid format", "cannot be blank"] }
|
80
|
+
# errors.to_hash(true) # => { email: ["email must be valid format", "email cannot be blank"] }
|
81
|
+
def to_hash(full = false)
|
82
|
+
full ? full_messages : to_h
|
83
|
+
end
|
84
|
+
|
61
85
|
# Convert errors to a human-readable string format.
|
62
86
|
#
|
63
87
|
# @return [String] Formatted error messages joined with periods
|
@@ -65,9 +89,7 @@ module CMDx
|
|
65
89
|
# @example
|
66
90
|
# errors.to_s # => "email must be valid format. email cannot be blank"
|
67
91
|
def to_s
|
68
|
-
|
69
|
-
messages.each { |message| memo << "#{attribute} #{message}" }
|
70
|
-
end.join(". ")
|
92
|
+
full_messages.values.flatten.join(". ")
|
71
93
|
end
|
72
94
|
|
73
95
|
end
|
data/lib/cmdx/result.rb
CHANGED
data/lib/cmdx/version.rb
CHANGED