gl_command 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c64386ffafec990d01604c12482b0cf2deb8b4caff95c638d9d4e8835c4cb92
4
- data.tar.gz: 9a58f0b30039b493382f01d22fb8cc2c8d6950af71f16ec3b4e708a776e78af9
3
+ metadata.gz: 72008b456b363007dc64f9701fb5e9241248527475df1900f8026d1f4fa1d63f
4
+ data.tar.gz: 368147f6acc900a820233283538ac7bcdb10c75ce0af3803076da9d87f919151
5
5
  SHA512:
6
- metadata.gz: 126e275c0bd65be3fb7fe1ead77e283231a158359b1c95ab00d691e010287f41b397a97a9202de316ba921313b1df66c59e76b4f5e13d62d4130d762aba6f803
7
- data.tar.gz: 728454632aa41f5b740b4f3eaf97c85ee8022857ac349ca86bfa0d655687fc6b402b7501629e580c3ed3c2b87b621a56a11333a95f3239d8ec0095901bb0e311
6
+ metadata.gz: 6ec728362eb5515db172717065350598ab7c1c636519a62e61c7c6e18b4a3cae724eff2feaa5845167f05f4c45d43d008a9df664bdb2c04c4ed427d1884765c3
7
+ data.tar.gz: 4314e4fb784d4c275585ba3952024189c76504a53a5d372b7239c4616ea08c5728237fd0bb6800acf23068189059be2de777e6b1d95063e6a68379a8eef5dc58
@@ -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 on a context, they expect to get the 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, "full_error_message: #{full_error_message}") if @failure && current_errors.blank?
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
- errors.import(new_error) unless errors&.full_messages&.include?(new_error.full_message)
157
+ current_errors.import(new_error) unless current_errors&.full_messages&.include?(new_error.full_message)
149
158
  end
150
159
  end
151
160
 
@@ -1,3 +1,3 @@
1
1
  module GLCommand
2
- VERSION = '1.1.1'.freeze
2
+ VERSION = '1.1.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gl_command
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Give Lively