lite-command 3.1.1 → 3.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/Gemfile.lock +2 -2
- data/README.md +3 -3
- data/lib/lite/command/base.rb +6 -6
- data/lib/lite/command/fault.rb +4 -4
- data/lib/lite/command/internals/attributes.rb +1 -2
- data/lib/lite/command/internals/calls.rb +19 -13
- data/lib/lite/command/internals/executions.rb +20 -7
- data/lib/lite/command/internals/faults.rb +3 -1
- data/lib/lite/command/internals/results.rb +2 -2
- data/lib/lite/command/utils.rb +4 -0
- data/lib/lite/command/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39377d9ecb58d9d61ae0c99305d9db08672b7f97eb368194fc209b419cec1d0a
|
4
|
+
data.tar.gz: 5ec36c8fcb1d68e2a6bd3ae0866f687a9c04469d502dcba0bc7fe092a9b88351
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 521be42ef9eab72ca99c2cd8dfba53ca3156538daf1e7715aff5123aefc6a70d7c4b439962306b8d1d22b87897bed1f54167353f98bea32d83ebf5eaaceffefe
|
7
|
+
data.tar.gz: 6c33d9b29e925c30b2e5abe06088fcfb0bccbd9cedbd241d76f398a89cfb7a679bf2a59b86ae766ccec69d94496640613d39995e9eca35ac3938d165a8e96eed
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [3.1.3] - 2024-10-26
|
10
|
+
### Added
|
11
|
+
- Added passing `original_exception` to fault `!` calls
|
12
|
+
### Changed
|
13
|
+
- Move monotonic clock to util
|
14
|
+
- Changed `metadata` to a keyword arg on fault `!` calls
|
15
|
+
### Removed
|
16
|
+
- Removed unnecessary `Lite::Command::` prefixes
|
17
|
+
- Removed double if/unless eval for required validations
|
18
|
+
|
19
|
+
## [3.1.2] - 2024-10-26
|
20
|
+
### Changed
|
21
|
+
- Make state set methods private
|
22
|
+
- Add returns for invalid state and status transitions
|
23
|
+
|
9
24
|
## [3.1.1] - 2024-10-25
|
10
25
|
### Changed
|
11
26
|
- Add option to raise original or fault exception
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
lite-command (3.1.
|
4
|
+
lite-command (3.1.3)
|
5
5
|
activemodel
|
6
6
|
ostruct
|
7
7
|
|
@@ -136,7 +136,7 @@ GEM
|
|
136
136
|
rubocop-ast (>= 1.31.1, < 2.0)
|
137
137
|
rubocop-rake (0.6.0)
|
138
138
|
rubocop (~> 1.0)
|
139
|
-
rubocop-rspec (3.
|
139
|
+
rubocop-rspec (3.2.0)
|
140
140
|
rubocop (~> 1.61)
|
141
141
|
ruby-progressbar (1.13.0)
|
142
142
|
securerandom (0.3.1)
|
data/README.md
CHANGED
@@ -334,7 +334,7 @@ class DecryptSecretMessage < Lite::Command::Base
|
|
334
334
|
if context.encrypted_message.empty?
|
335
335
|
noop!("No message to decrypt")
|
336
336
|
elsif context.encrypted_message.start_with?("== womp")
|
337
|
-
invalid!("Invalid message start value", i18n: "gb.invalid_start_value")
|
337
|
+
invalid!("Invalid message start value", metadata: { i18n: "gb.invalid_start_value" })
|
338
338
|
elsif context.encrypted_message.algo?(OldAlgo)
|
339
339
|
failure!("Unsafe encryption algo detected")
|
340
340
|
else
|
@@ -342,7 +342,7 @@ class DecryptSecretMessage < Lite::Command::Base
|
|
342
342
|
end
|
343
343
|
rescue CryptoError => e
|
344
344
|
Apm.report_error(e)
|
345
|
-
error!("Failed decryption due to: #{e}")
|
345
|
+
error!("Failed decryption due to: #{e}", original_exception: e)
|
346
346
|
end
|
347
347
|
|
348
348
|
end
|
@@ -541,7 +541,7 @@ class DecryptSecretMessage < Lite::Command::Base
|
|
541
541
|
cmd = ValidateSecretMessage.call(context)
|
542
542
|
|
543
543
|
if cmd.invalid?("Invalid magic numbers")
|
544
|
-
|
544
|
+
failure!(cmd) # Manually throw a specific fault
|
545
545
|
elsif command.fault?
|
546
546
|
throw!(cmd) # Automatically throws a matching fault
|
547
547
|
else
|
data/lib/lite/command/base.rb
CHANGED
@@ -11,11 +11,11 @@ module Lite
|
|
11
11
|
|
12
12
|
base.include ActiveModel::Validations
|
13
13
|
|
14
|
-
base.include
|
15
|
-
base.include
|
16
|
-
base.include
|
17
|
-
base.include
|
18
|
-
base.include
|
14
|
+
base.include Internals::Attributes
|
15
|
+
base.include Internals::Calls
|
16
|
+
base.include Internals::Executions
|
17
|
+
base.include Internals::Faults
|
18
|
+
base.include Internals::Results
|
19
19
|
|
20
20
|
if Lite::Command.configuration.raise_dynamic_faults # rubocop:disable Style/GuardClause
|
21
21
|
base.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
@@ -32,7 +32,7 @@ module Lite
|
|
32
32
|
alias ctx context
|
33
33
|
|
34
34
|
def initialize(context = {})
|
35
|
-
@context =
|
35
|
+
@context = Context.build(context)
|
36
36
|
Utils.try(self, :on_pending)
|
37
37
|
end
|
38
38
|
|
data/lib/lite/command/fault.rb
CHANGED
@@ -29,16 +29,16 @@ module Lite
|
|
29
29
|
fault
|
30
30
|
end
|
31
31
|
|
32
|
-
def self.===(
|
33
|
-
Utils.descendant_of?(self,
|
32
|
+
def self.===(object)
|
33
|
+
Utils.descendant_of?(self, object) || Utils.descendant_of?(object, self)
|
34
34
|
end
|
35
35
|
|
36
36
|
def type
|
37
37
|
@type ||= self.class.name.split("::").last.downcase
|
38
38
|
end
|
39
39
|
|
40
|
-
def ===(
|
41
|
-
Utils.descendant_of?(self,
|
40
|
+
def ===(object)
|
41
|
+
Utils.descendant_of?(self, object)
|
42
42
|
end
|
43
43
|
|
44
44
|
end
|
@@ -15,7 +15,6 @@ module Lite
|
|
15
15
|
delegate(*attributes, from:)
|
16
16
|
|
17
17
|
validates_each(*attributes, **options) do |command, method_name, _attr_value|
|
18
|
-
next unless Utils.evaluate(command, options)
|
19
18
|
next if command.errors.added?(from, :undefined) || command.errors.added?(method_name, :required)
|
20
19
|
|
21
20
|
if !command.respond_to?(from, true)
|
@@ -55,7 +54,7 @@ module Lite
|
|
55
54
|
def validate_context_attributes
|
56
55
|
return if errors.empty?
|
57
56
|
|
58
|
-
invalid!(errors.full_messages.join(". "), errors.messages)
|
57
|
+
invalid!(errors.full_messages.join(". "), metadata: errors.messages)
|
59
58
|
end
|
60
59
|
|
61
60
|
end
|
@@ -59,7 +59,7 @@ module Lite
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def bad?(reason = nil)
|
62
|
-
!
|
62
|
+
!ok?(reason)
|
63
63
|
end
|
64
64
|
|
65
65
|
FAULTS.each do |f|
|
@@ -75,23 +75,29 @@ module Lite
|
|
75
75
|
str.nil? || str == reason
|
76
76
|
end
|
77
77
|
|
78
|
-
def fault(object,
|
79
|
-
|
80
|
-
@metadata = metadata
|
78
|
+
def fault(object, s, m, oe) # rubocop:disable Naming/MethodParameterName
|
79
|
+
return if s == SUCCESS || status != SUCCESS
|
81
80
|
|
82
|
-
|
83
|
-
@
|
84
|
-
@metadata ||= down_stream.metadata
|
85
|
-
@caused_by ||= down_stream.caused_by
|
86
|
-
@thrown_by ||= down_stream.thrown_by
|
81
|
+
@status = s
|
82
|
+
@metadata = m
|
87
83
|
|
88
|
-
|
84
|
+
fault_streamer = FaultStreamer.new(self, object)
|
85
|
+
@reason ||= fault_streamer.reason
|
86
|
+
@metadata ||= fault_streamer.metadata
|
87
|
+
@caused_by ||= fault_streamer.caused_by
|
88
|
+
@thrown_by ||= fault_streamer.thrown_by
|
89
|
+
|
90
|
+
@fault_exception ||= fault_streamer.fault_exception
|
91
|
+
@original_exception ||= oe || fault_exception
|
89
92
|
end
|
90
93
|
|
91
94
|
FAULTS.each do |f|
|
92
|
-
# eg: invalid!("idk") or failure!(fault) or error!("idk", { error_key: "some.error" })
|
93
|
-
define_method(:"#{f}!") do |object, metadata
|
94
|
-
|
95
|
+
# eg: invalid!("idk") or failure!(fault) or error!("idk", metadata: { error_key: "some.error" }, original_exception: err)
|
96
|
+
define_method(:"#{f}!") do |object, metadata: nil, original_exception: nil|
|
97
|
+
return unless success?
|
98
|
+
|
99
|
+
fault(object, f, metadata, original_exception)
|
100
|
+
|
95
101
|
raise(fault_exception)
|
96
102
|
end
|
97
103
|
end
|
@@ -24,13 +24,28 @@ module Lite
|
|
24
24
|
STATES.each do |s|
|
25
25
|
# eg: executing?
|
26
26
|
define_method(:"#{s}?") { state == s }
|
27
|
-
|
28
|
-
# eg: interrupted!
|
29
|
-
define_method(:"#{s}!") { @state = s }
|
30
27
|
end
|
31
28
|
|
32
29
|
private
|
33
30
|
|
31
|
+
def executing!
|
32
|
+
return unless pending?
|
33
|
+
|
34
|
+
@state = EXECUTING
|
35
|
+
end
|
36
|
+
|
37
|
+
def complete!
|
38
|
+
return if executed?
|
39
|
+
|
40
|
+
@state = COMPLETE
|
41
|
+
end
|
42
|
+
|
43
|
+
def interrupted!
|
44
|
+
return if executed?
|
45
|
+
|
46
|
+
@state = INTERRUPTED
|
47
|
+
end
|
48
|
+
|
34
49
|
def before_execution
|
35
50
|
increment_execution_index
|
36
51
|
assign_execution_cmd_id
|
@@ -60,8 +75,7 @@ module Lite
|
|
60
75
|
around_execution { call }
|
61
76
|
Utils.try(self, :on_success)
|
62
77
|
rescue StandardError => e
|
63
|
-
|
64
|
-
fault(e, ERROR, metadata) unless e.is_a?(Lite::Command::Fault)
|
78
|
+
fault(e, ERROR, metadata, e)
|
65
79
|
after_execution
|
66
80
|
Utils.try(self, :"on_#{status}", e)
|
67
81
|
ensure
|
@@ -72,8 +86,7 @@ module Lite
|
|
72
86
|
around_execution { call }
|
73
87
|
Utils.try(self, :on_success)
|
74
88
|
rescue StandardError => e
|
75
|
-
|
76
|
-
fault(e, ERROR, metadata) unless e.is_a?(Lite::Command::Fault)
|
89
|
+
fault(e, ERROR, metadata, e)
|
77
90
|
after_execution
|
78
91
|
Utils.try(self, :"on_#{status}", e)
|
79
92
|
raise(e)
|
@@ -53,11 +53,11 @@ module Lite
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def start_monotonic_time
|
56
|
-
@start_monotonic_time ||=
|
56
|
+
@start_monotonic_time ||= Utils.monotonic_time
|
57
57
|
end
|
58
58
|
|
59
59
|
def stop_monotonic_time
|
60
|
-
@stop_monotonic_time ||=
|
60
|
+
@stop_monotonic_time ||= Utils.monotonic_time
|
61
61
|
end
|
62
62
|
|
63
63
|
def runtime
|
data/lib/lite/command/utils.rb
CHANGED
@@ -6,6 +6,10 @@ module Lite
|
|
6
6
|
|
7
7
|
module_function
|
8
8
|
|
9
|
+
def monotonic_time
|
10
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
11
|
+
end
|
12
|
+
|
9
13
|
def descendant_of?(object, other)
|
10
14
|
object_class = object.respond_to?(:new) ? object : object.class
|
11
15
|
other_class = other.respond_to?(:new) ? other : other.class
|
data/lib/lite/command/version.rb
CHANGED