gl_command 1.1.2 → 1.1.3
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/README.md +18 -0
- data/gl_command.gemspec +3 -2
- data/lib/gl_command/chainable.rb +8 -7
- data/lib/gl_command/context.rb +6 -2
- data/lib/gl_command/context_inspect.rb +33 -35
- data/lib/gl_command/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '09bb7724a153ffb2e0f53a71bac270a2410df26bb4b145e776e381f41dff3fff'
|
4
|
+
data.tar.gz: 0a882a14125ac56b3dc132954382b01fa0722349ac1fd74605296f760167e751
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44e04e38a4537e47d8be1614e7d0b8e04c759f83f467a1aa9fde1d372b70ec000163277637b502254006f50f5f950c76a886012606c1c0396a74e9256b5742b2
|
7
|
+
data.tar.gz: f5b28a4e1933b2c89d33d7f435a552430bfe4c7bbe8464fba15e1fb6b9367a37e4e870a5f268d96a64a2fb736929b1a0805b8f5ee5102e5185d32816cf74377d
|
data/README.md
CHANGED
@@ -195,6 +195,24 @@ class SomeChain < GLCommand::Chainable
|
|
195
195
|
end
|
196
196
|
end
|
197
197
|
```
|
198
|
+
And if you need to return early (and skip the `chain`), call `skip_chain` - or else you will get an error: `#chain method not called in GLCommand::Chainable #call.`
|
199
|
+
|
200
|
+
```ruby
|
201
|
+
class SomeChain < GLCommand::Chainable
|
202
|
+
requires :item
|
203
|
+
|
204
|
+
returns :new_item
|
205
|
+
|
206
|
+
chain CommmandOne, CommandTwo
|
207
|
+
|
208
|
+
def call
|
209
|
+
skip_chain unless item.valid? # Automatically skips the whole chain without any errors
|
210
|
+
|
211
|
+
chain(:item)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
```
|
198
216
|
|
199
217
|
|
200
218
|
---
|
data/gl_command.gemspec
CHANGED
@@ -8,12 +8,13 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.authors = ['Give Lively']
|
9
9
|
spec.summary = 'Give Lively Commands'
|
10
10
|
spec.homepage = 'https://github.com/givelively/gl_command'
|
11
|
-
spec.license = 'Apache'
|
11
|
+
spec.license = 'Apache-2.0'
|
12
12
|
spec.platform = Gem::Platform::RUBY
|
13
13
|
|
14
14
|
spec.required_ruby_version = '>= 3.1'
|
15
15
|
spec.extra_rdoc_files = ['README.md']
|
16
|
-
spec.files = %w[gl_command.gemspec README.md
|
16
|
+
spec.files = %w[gl_command.gemspec README.md
|
17
|
+
LICENSE] + `git ls-files | grep -E '^(lib)'`.split("\n")
|
17
18
|
|
18
19
|
spec.add_dependency 'activerecord', '>= 3.2.0'
|
19
20
|
spec.add_dependency 'gl_exception_notifier', '>= 1.0.2'
|
data/lib/gl_command/chainable.rb
CHANGED
@@ -32,7 +32,7 @@ module GLCommand
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
35
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Lint/UnderscorePrefixedVariableName
|
36
36
|
def chain(args)
|
37
37
|
return if @chain_skipped
|
38
38
|
|
@@ -43,20 +43,21 @@ module GLCommand
|
|
43
43
|
cargs = context.chain_arguments_and_returns.slice(*command.arguments)
|
44
44
|
.merge(context.opts_hash).merge(in_chain: true)
|
45
45
|
|
46
|
-
|
47
|
-
|
46
|
+
# using _result to make sure it doesn't cause naming conflicts with other uses of result
|
47
|
+
_result = command.call(**cargs)
|
48
|
+
context.assign_parameters(skip_unknown_parameters: true, **_result.returns)
|
48
49
|
|
49
|
-
if
|
50
|
+
if _result.success?
|
50
51
|
context.called << command
|
51
52
|
else
|
52
53
|
@notified = true # chained command already notified
|
53
|
-
errors
|
54
|
-
stop_and_fail!(
|
54
|
+
errors&.merge!(_result.errors)
|
55
|
+
stop_and_fail!(_result.error, no_notify: _result.no_notify?)
|
55
56
|
break
|
56
57
|
end
|
57
58
|
end
|
58
59
|
end
|
59
|
-
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
60
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Lint/UnderscorePrefixedVariableName
|
60
61
|
|
61
62
|
def commands
|
62
63
|
self.class.commands
|
data/lib/gl_command/context.rb
CHANGED
@@ -101,7 +101,9 @@ module GLCommand
|
|
101
101
|
if exception?(passed_error)
|
102
102
|
# This catches errors within GLCommand::Context and prevents self referential error display
|
103
103
|
# $ERROR_INFO (aka $!), stores the last Ruby error
|
104
|
-
|
104
|
+
if $ERROR_INFO.to_s.include?('for <GLCommand::Context')
|
105
|
+
@full_error_message ||= $ERROR_INFO.to_s
|
106
|
+
end
|
105
107
|
# If something raised ActiveRecord::RecordInvalid, assign its errors to #errors
|
106
108
|
merge_errors(passed_error.record.errors) if
|
107
109
|
passed_error.is_a?(ActiveRecord::RecordInvalid) && defined?(passed_error.record.errors)
|
@@ -154,7 +156,9 @@ module GLCommand
|
|
154
156
|
def merge_errors(new_errors)
|
155
157
|
# When merging the errors, don't add duplicate errors
|
156
158
|
new_errors.each do |new_error|
|
157
|
-
|
159
|
+
unless current_errors&.full_messages&.include?(new_error.full_message)
|
160
|
+
current_errors.import(new_error)
|
161
|
+
end
|
158
162
|
end
|
159
163
|
end
|
160
164
|
|
@@ -1,44 +1,42 @@
|
|
1
1
|
module GLCommand
|
2
2
|
class ContextInspect
|
3
|
-
|
4
|
-
|
3
|
+
class << self
|
4
|
+
def error(error_obj)
|
5
|
+
return '' if error_obj.blank?
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
error_obj.is_a?(Array) ? error_obj.uniq.join(', ') : error_obj.to_s
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
10
|
+
def hash_params(hash)
|
11
|
+
hash.map do |key, value|
|
12
|
+
value_s =
|
13
|
+
if value.nil?
|
14
|
+
'nil'
|
15
|
+
elsif value.respond_to?(:to_sql)
|
16
|
+
object_param_as_sql(value)
|
17
|
+
elsif value.respond_to?(:uuid)
|
18
|
+
object_param_with_id(value, :uuid)
|
19
|
+
elsif value.respond_to?(:id)
|
20
|
+
object_param_with_id(value, :id)
|
21
|
+
else
|
22
|
+
value
|
23
|
+
end
|
24
|
+
"#{key}: #{value_s}"
|
25
|
+
end.join(', ')
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
private
|
29
|
+
|
30
|
+
# Active record objects can be really big - rather than rendering the whole object, just show the ID
|
31
|
+
def object_param_with_id(obj, key)
|
32
|
+
obj_id = obj.send(key)
|
33
|
+
id_value = obj_id.is_a?(Integer) ? obj_id : "\"#{obj_id}\""
|
34
|
+
"#<#{obj.class.name} #{key}=#{id_value}>"
|
35
|
+
end
|
33
36
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
obj.count
|
38
|
-
else
|
39
|
-
'N/A'
|
40
|
-
end
|
41
|
-
"#<#{obj.class.name} count=#{count}, sql=\"#{obj.to_sql}\">"
|
37
|
+
def object_param_as_sql(obj)
|
38
|
+
"#<#{obj.class.name} sql=\"#{obj.to_sql}\">"
|
39
|
+
end
|
42
40
|
end
|
43
41
|
end
|
44
42
|
end
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Give Lively
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -58,7 +58,7 @@ files:
|
|
58
58
|
- lib/gl_command/version.rb
|
59
59
|
homepage: https://github.com/givelively/gl_command
|
60
60
|
licenses:
|
61
|
-
- Apache
|
61
|
+
- Apache-2.0
|
62
62
|
metadata:
|
63
63
|
rubygems_mfa_required: 'true'
|
64
64
|
post_install_message:
|