gl_command 1.1.0 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gl_command/callable.rb +6 -2
- data/lib/gl_command/context.rb +22 -4
- 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: 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/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,11 @@ module GLCommand
|
|
25
25
|
attr_reader :klass, :error
|
26
26
|
attr_writer :full_error_message
|
27
27
|
|
28
|
-
|
28
|
+
# If someone calls #errors, they expect to get the errors! Include the non-validation error, if it exists
|
29
|
+
def errors
|
30
|
+
current_errors&.add(:base, "Command Error: #{full_error_message}") if add_command_error?
|
31
|
+
current_errors
|
32
|
+
end
|
29
33
|
|
30
34
|
def chain?
|
31
35
|
false
|
@@ -48,7 +52,7 @@ module GLCommand
|
|
48
52
|
end
|
49
53
|
|
50
54
|
def failure?
|
51
|
-
@failure ||
|
55
|
+
@failure || current_errors.present? || @full_error_message.present? || false
|
52
56
|
end
|
53
57
|
|
54
58
|
def success?
|
@@ -103,7 +107,7 @@ module GLCommand
|
|
103
107
|
passed_error.is_a?(ActiveRecord::RecordInvalid) && defined?(passed_error.record.errors)
|
104
108
|
# Return a new error if it's an error (rather than the class)
|
105
109
|
passed_error.is_a?(Class) ? passed_error.new(@full_error_message) : passed_error
|
106
|
-
elsif
|
110
|
+
elsif current_errors.present? # check for validation errors
|
107
111
|
# Assign ActiveRecord::RecordInvalid if validatable error
|
108
112
|
ActiveRecord::RecordInvalid.new(@callable)
|
109
113
|
else
|
@@ -123,6 +127,20 @@ module GLCommand
|
|
123
127
|
|
124
128
|
private
|
125
129
|
|
130
|
+
def current_errors
|
131
|
+
@callable&.errors
|
132
|
+
end
|
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
|
+
|
126
144
|
def exception?(passed_error)
|
127
145
|
passed_error.is_a?(Exception) ||
|
128
146
|
(passed_error.respond_to?(:ancestors) && passed_error.ancestors.include?(Exception))
|
@@ -136,7 +154,7 @@ module GLCommand
|
|
136
154
|
def merge_errors(new_errors)
|
137
155
|
# When merging the errors, don't add duplicate errors
|
138
156
|
new_errors.each do |new_error|
|
139
|
-
|
157
|
+
current_errors.import(new_error) unless current_errors&.full_messages&.include?(new_error.full_message)
|
140
158
|
end
|
141
159
|
end
|
142
160
|
|
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.2
|
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
|