gl_command 1.1.0 → 1.1.1

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: b0e88d785a51d72653d8691d86236df3791dadaa84b46a548895e045509e1428
4
- data.tar.gz: 582d39e38c74b40ac251dd91071fe602a8860f6ecda15a7ece244e21541352d1
3
+ metadata.gz: 2c64386ffafec990d01604c12482b0cf2deb8b4caff95c638d9d4e8835c4cb92
4
+ data.tar.gz: 9a58f0b30039b493382f01d22fb8cc2c8d6950af71f16ec3b4e708a776e78af9
5
5
  SHA512:
6
- metadata.gz: e8758b174cdf1f76a4b35d466876a8fbaa848f2546628ea777e7db594a1221a3ca9db2c31f0be77a6d58c62a739f62294e23e63050ed76bd48ca85fcbbfcdb0b
7
- data.tar.gz: ed20e53cb69da3c59f2919e7f89c505d2470a9fa44138fdd9334c12c6bebcb1c89dd34a9598b9f33a0c0a29ea875fefa7f10c89e16a2d0cfe07fb1bcb133c392
6
+ metadata.gz: 126e275c0bd65be3fb7fe1ead77e283231a158359b1c95ab00d691e010287f41b397a97a9202de316ba921313b1df66c59e76b4f5e13d62d4130d762aba6f803
7
+ data.tar.gz: 728454632aa41f5b740b4f3eaf97c85ee8022857ac349ca86bfa0d655687fc6b402b7501629e580c3ed3c2b87b621a56a11333a95f3239d8ec0095901bb0e311
@@ -35,9 +35,13 @@ module GLCommand
35
35
  call(*posargs, **args.merge(raise_errors: true))
36
36
  end
37
37
 
38
- def build_context(raise_errors: false, skip_unknown_parameters: false,
38
+ # error can be passed to build context, useful for stubbing in tests
39
+ def build_context(raise_errors: false, skip_unknown_parameters: false, error: nil,
39
40
  **arguments_and_returns)
40
- context_class.new(self, raise_errors:, skip_unknown_parameters:, **arguments_and_returns)
41
+ new_context = context_class.new(self, raise_errors:, skip_unknown_parameters:,
42
+ **arguments_and_returns)
43
+ new_context.error = error if error.present?
44
+ new_context
41
45
  end
42
46
 
43
47
  def requires(*attributes, **strong_attributes)
@@ -25,7 +25,12 @@ module GLCommand
25
25
  attr_reader :klass, :error
26
26
  attr_writer :full_error_message
27
27
 
28
- delegate :errors, to: :@callable, allow_nil: true
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
30
+ def errors
31
+ current_errors&.add(:base, "full_error_message: #{full_error_message}") if @failure && current_errors.blank?
32
+ current_errors
33
+ end
29
34
 
30
35
  def chain?
31
36
  false
@@ -48,7 +53,7 @@ module GLCommand
48
53
  end
49
54
 
50
55
  def failure?
51
- @failure || errors.present? || @full_error_message.present? || false
56
+ @failure || current_errors.present? || @full_error_message.present? || false
52
57
  end
53
58
 
54
59
  def success?
@@ -103,7 +108,7 @@ module GLCommand
103
108
  passed_error.is_a?(ActiveRecord::RecordInvalid) && defined?(passed_error.record.errors)
104
109
  # Return a new error if it's an error (rather than the class)
105
110
  passed_error.is_a?(Class) ? passed_error.new(@full_error_message) : passed_error
106
- elsif errors.present? # check for validation errors
111
+ elsif current_errors.present? # check for validation errors
107
112
  # Assign ActiveRecord::RecordInvalid if validatable error
108
113
  ActiveRecord::RecordInvalid.new(@callable)
109
114
  else
@@ -123,6 +128,10 @@ module GLCommand
123
128
 
124
129
  private
125
130
 
131
+ def current_errors
132
+ @callable&.errors
133
+ end
134
+
126
135
  def exception?(passed_error)
127
136
  passed_error.is_a?(Exception) ||
128
137
  (passed_error.respond_to?(:ancestors) && passed_error.ancestors.include?(Exception))
@@ -1,3 +1,3 @@
1
1
  module GLCommand
2
- VERSION = '1.1.0'.freeze
2
+ VERSION = '1.1.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gl_command
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Give Lively
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-28 00:00:00.000000000 Z
11
+ date: 2024-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord