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 +4 -4
- data/lib/gl_command/callable.rb +6 -2
- data/lib/gl_command/context.rb +12 -3
- data/lib/gl_command/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c64386ffafec990d01604c12482b0cf2deb8b4caff95c638d9d4e8835c4cb92
|
4
|
+
data.tar.gz: 9a58f0b30039b493382f01d22fb8cc2c8d6950af71f16ec3b4e708a776e78af9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 126e275c0bd65be3fb7fe1ead77e283231a158359b1c95ab00d691e010287f41b397a97a9202de316ba921313b1df66c59e76b4f5e13d62d4130d762aba6f803
|
7
|
+
data.tar.gz: 728454632aa41f5b740b4f3eaf97c85ee8022857ac349ca86bfa0d655687fc6b402b7501629e580c3ed3c2b87b621a56a11333a95f3239d8ec0095901bb0e311
|
data/lib/gl_command/callable.rb
CHANGED
@@ -35,9 +35,13 @@ module GLCommand
|
|
35
35
|
call(*posargs, **args.merge(raise_errors: true))
|
36
36
|
end
|
37
37
|
|
38
|
-
|
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:,
|
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)
|
data/lib/gl_command/context.rb
CHANGED
@@ -25,7 +25,12 @@ module GLCommand
|
|
25
25
|
attr_reader :klass, :error
|
26
26
|
attr_writer :full_error_message
|
27
27
|
|
28
|
-
|
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 ||
|
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
|
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))
|
data/lib/gl_command/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2024-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|