gl_command 1.1.1 → 1.1.2
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/lib/gl_command/context.rb +13 -4
- data/lib/gl_command/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: 72008b456b363007dc64f9701fb5e9241248527475df1900f8026d1f4fa1d63f
|
4
|
+
data.tar.gz: 368147f6acc900a820233283538ac7bcdb10c75ce0af3803076da9d87f919151
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ec728362eb5515db172717065350598ab7c1c636519a62e61c7c6e18b4a3cae724eff2feaa5845167f05f4c45d43d008a9df664bdb2c04c4ed427d1884765c3
|
7
|
+
data.tar.gz: 4314e4fb784d4c275585ba3952024189c76504a53a5d372b7239c4616ea08c5728237fd0bb6800acf23068189059be2de777e6b1d95063e6a68379a8eef5dc58
|
data/lib/gl_command/context.rb
CHANGED
@@ -25,10 +25,9 @@ module GLCommand
|
|
25
25
|
attr_reader :klass, :error
|
26
26
|
attr_writer :full_error_message
|
27
27
|
|
28
|
-
# If someone calls errors
|
29
|
-
# Make that work, but also try to make it clear that they probably shouldn't be using that for presentation
|
28
|
+
# If someone calls #errors, they expect to get the errors! Include the non-validation error, if it exists
|
30
29
|
def errors
|
31
|
-
current_errors&.add(:base, "
|
30
|
+
current_errors&.add(:base, "Command Error: #{full_error_message}") if add_command_error?
|
32
31
|
current_errors
|
33
32
|
end
|
34
33
|
|
@@ -132,6 +131,16 @@ module GLCommand
|
|
132
131
|
@callable&.errors
|
133
132
|
end
|
134
133
|
|
134
|
+
def add_command_error?
|
135
|
+
return false if @error.blank?
|
136
|
+
|
137
|
+
return true if current_errors.blank?
|
138
|
+
|
139
|
+
# Add command error unless the existing error is a validation error or there's already a command error
|
140
|
+
@error&.class != ActiveRecord::RecordInvalid &&
|
141
|
+
current_errors.full_messages.none? { |err| err.start_with?('Command Error: ') }
|
142
|
+
end
|
143
|
+
|
135
144
|
def exception?(passed_error)
|
136
145
|
passed_error.is_a?(Exception) ||
|
137
146
|
(passed_error.respond_to?(:ancestors) && passed_error.ancestors.include?(Exception))
|
@@ -145,7 +154,7 @@ module GLCommand
|
|
145
154
|
def merge_errors(new_errors)
|
146
155
|
# When merging the errors, don't add duplicate errors
|
147
156
|
new_errors.each do |new_error|
|
148
|
-
|
157
|
+
current_errors.import(new_error) unless current_errors&.full_messages&.include?(new_error.full_message)
|
149
158
|
end
|
150
159
|
end
|
151
160
|
|
data/lib/gl_command/version.rb
CHANGED