gl_command 1.0.1 → 1.1.0
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 +13 -5
- data/lib/gl_command/chainable.rb +1 -1
- data/lib/gl_command/context.rb +6 -1
- 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: b0e88d785a51d72653d8691d86236df3791dadaa84b46a548895e045509e1428
|
4
|
+
data.tar.gz: 582d39e38c74b40ac251dd91071fe602a8860f6ecda15a7ece244e21541352d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8758b174cdf1f76a4b35d466876a8fbaa848f2546628ea777e7db594a1221a3ca9db2c31f0be77a6d58c62a739f62294e23e63050ed76bd48ca85fcbbfcdb0b
|
7
|
+
data.tar.gz: ed20e53cb69da3c59f2919e7f89c505d2470a9fa44138fdd9334c12c6bebcb1c89dd34a9598b9f33a0c0a29ea875fefa7f10c89e16a2d0cfe07fb1bcb133c392
|
data/lib/gl_command/callable.rb
CHANGED
@@ -6,7 +6,7 @@ require 'gl_command/validatable'
|
|
6
6
|
|
7
7
|
module GLCommand
|
8
8
|
class Callable
|
9
|
-
DEFAULT_OPTS = { raise_errors: false, skip_unknown_parameters: true }.freeze
|
9
|
+
DEFAULT_OPTS = { raise_errors: false, skip_unknown_parameters: true, in_chain: false }.freeze
|
10
10
|
RESERVED_WORDS = (DEFAULT_OPTS.keys + GLCommand::ChainableContext.reserved_words).sort.freeze
|
11
11
|
|
12
12
|
class << self
|
@@ -25,7 +25,8 @@ module GLCommand
|
|
25
25
|
|
26
26
|
# DEFAULT_OPTS contains skip_unknown_parameters: true - so it raises on call
|
27
27
|
# (rather than in context initialize) to make errors more legible
|
28
|
-
opts = DEFAULT_OPTS.merge(raise_errors: args.delete(:raise_errors)
|
28
|
+
opts = DEFAULT_OPTS.merge(raise_errors: args.delete(:raise_errors),
|
29
|
+
in_chain: args.delete(:in_chain)).compact
|
29
30
|
# args are passed in in perform_call(args) so that invalid args raise in a legible place
|
30
31
|
new(build_context(**args.merge(opts))).perform_call(args)
|
31
32
|
end
|
@@ -70,7 +71,7 @@ module GLCommand
|
|
70
71
|
(arguments + returns).uniq
|
71
72
|
end
|
72
73
|
|
73
|
-
# Used internally by GLCommand (probably don't reference
|
74
|
+
# Used internally by GLCommand (probably don't reference in your own GLCommands)
|
74
75
|
# is true in GLCommand::Chainable
|
75
76
|
def chain?
|
76
77
|
false
|
@@ -106,7 +107,9 @@ module GLCommand
|
|
106
107
|
|
107
108
|
def perform_call(args)
|
108
109
|
raise_for_invalid_args!(**args)
|
110
|
+
instrument_command(:before_call)
|
109
111
|
call_with_callbacks
|
112
|
+
instrument_command(:after_call)
|
110
113
|
raise_unless_chained_or_skipped if self.class.chain? # defined in GLCommand::Chainable
|
111
114
|
context.failure? ? handle_failure : context
|
112
115
|
rescue StandardError => e
|
@@ -133,6 +136,11 @@ module GLCommand
|
|
133
136
|
|
134
137
|
private
|
135
138
|
|
139
|
+
# trigger: [:before_call, :after_call, :before_rollback]
|
140
|
+
def instrument_command(trigger)
|
141
|
+
# Override where gem is used if you want to instrument commands
|
142
|
+
end
|
143
|
+
|
136
144
|
# rubocop:disable Metrics/AbcSize
|
137
145
|
def handle_failure(e = nil)
|
138
146
|
context.error ||= e
|
@@ -159,9 +167,7 @@ module GLCommand
|
|
159
167
|
rescue GLCommand::CommandNoNotifyError
|
160
168
|
raise context.error # makes CommandNoNotifyError the cause
|
161
169
|
end
|
162
|
-
# rubocop:enable Metrics/AbcSize
|
163
170
|
|
164
|
-
# rubocop:disable Metrics/AbcSize
|
165
171
|
def call_with_callbacks
|
166
172
|
GLExceptionNotifier.breadcrumbs(data: { context: context.inspect }, message: self.class.to_s)
|
167
173
|
validate_validatable! # defined in GLCommand::Validatable
|
@@ -186,6 +192,8 @@ module GLCommand
|
|
186
192
|
def call_rollbacks
|
187
193
|
return if defined?(@rolled_back) # Not sure this is required
|
188
194
|
|
195
|
+
instrument_command(:before_rollback)
|
196
|
+
|
189
197
|
@rolled_back = true
|
190
198
|
|
191
199
|
chain_rollback if self.class.chain? # defined in GLCommand::Chainable
|
data/lib/gl_command/chainable.rb
CHANGED
@@ -41,7 +41,7 @@ module GLCommand
|
|
41
41
|
|
42
42
|
commands.map do |command|
|
43
43
|
cargs = context.chain_arguments_and_returns.slice(*command.arguments)
|
44
|
-
.merge(context.opts_hash)
|
44
|
+
.merge(context.opts_hash).merge(in_chain: true)
|
45
45
|
|
46
46
|
result = command.call(**cargs)
|
47
47
|
context.assign_parameters(skip_unknown_parameters: true, **result.returns)
|
data/lib/gl_command/context.rb
CHANGED
@@ -7,9 +7,10 @@ require 'active_support/core_ext/module'
|
|
7
7
|
module GLCommand
|
8
8
|
class Context
|
9
9
|
def initialize(klass, raise_errors: false, skip_unknown_parameters: false,
|
10
|
-
**arguments_and_returns)
|
10
|
+
in_chain: false, **arguments_and_returns)
|
11
11
|
@klass = klass
|
12
12
|
@raise_errors = raise_errors.nil? ? false : raise_errors
|
13
|
+
@in_chain = in_chain
|
13
14
|
@klass.arguments_and_returns.each { |key| singleton_class.class_eval { attr_accessor key } }
|
14
15
|
initialize_chain_context(**arguments_and_returns) if chain?
|
15
16
|
assign_parameters(skip_unknown_parameters:, **arguments_and_returns)
|
@@ -30,6 +31,10 @@ module GLCommand
|
|
30
31
|
false
|
31
32
|
end
|
32
33
|
|
34
|
+
def in_chain?
|
35
|
+
@in_chain
|
36
|
+
end
|
37
|
+
|
33
38
|
def returns
|
34
39
|
@klass.returns.index_with { |rattr| send(rattr) }
|
35
40
|
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.0
|
4
|
+
version: 1.1.0
|
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-
|
11
|
+
date: 2024-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|