lite-command 3.1.2 → 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 +10 -0
- data/Gemfile.lock +1 -1
- 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 +9 -6
- data/lib/lite/command/internals/executions.rb +2 -4
- 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,16 @@ 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
|
+
|
9
19
|
## [3.1.2] - 2024-10-26
|
10
20
|
### Changed
|
11
21
|
- Make state set methods private
|
data/Gemfile.lock
CHANGED
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
|
@@ -75,26 +75,29 @@ module Lite
|
|
75
75
|
str.nil? || str == reason
|
76
76
|
end
|
77
77
|
|
78
|
-
def fault(object, s, m) # rubocop:disable Naming/MethodParameterName
|
78
|
+
def fault(object, s, m, oe) # rubocop:disable Naming/MethodParameterName
|
79
79
|
return if s == SUCCESS || status != SUCCESS
|
80
80
|
|
81
81
|
@status = s
|
82
82
|
@metadata = m
|
83
83
|
|
84
|
-
fault_streamer =
|
84
|
+
fault_streamer = FaultStreamer.new(self, object)
|
85
85
|
@reason ||= fault_streamer.reason
|
86
86
|
@metadata ||= fault_streamer.metadata
|
87
87
|
@caused_by ||= fault_streamer.caused_by
|
88
88
|
@thrown_by ||= fault_streamer.thrown_by
|
89
|
-
|
89
|
+
|
90
|
+
@fault_exception ||= fault_streamer.fault_exception
|
91
|
+
@original_exception ||= oe || fault_exception
|
90
92
|
end
|
91
93
|
|
92
94
|
FAULTS.each do |f|
|
93
|
-
# eg: invalid!("idk") or failure!(fault) or error!("idk", { error_key: "some.error" })
|
94
|
-
define_method(:"#{f}!") do |object, metadata
|
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|
|
95
97
|
return unless success?
|
96
98
|
|
97
|
-
fault(object, f, metadata)
|
99
|
+
fault(object, f, metadata, original_exception)
|
100
|
+
|
98
101
|
raise(fault_exception)
|
99
102
|
end
|
100
103
|
end
|
@@ -75,8 +75,7 @@ module Lite
|
|
75
75
|
around_execution { call }
|
76
76
|
Utils.try(self, :on_success)
|
77
77
|
rescue StandardError => e
|
78
|
-
|
79
|
-
fault(e, ERROR, metadata)
|
78
|
+
fault(e, ERROR, metadata, e)
|
80
79
|
after_execution
|
81
80
|
Utils.try(self, :"on_#{status}", e)
|
82
81
|
ensure
|
@@ -87,8 +86,7 @@ module Lite
|
|
87
86
|
around_execution { call }
|
88
87
|
Utils.try(self, :on_success)
|
89
88
|
rescue StandardError => e
|
90
|
-
|
91
|
-
fault(e, ERROR, metadata)
|
89
|
+
fault(e, ERROR, metadata, e)
|
92
90
|
after_execution
|
93
91
|
Utils.try(self, :"on_#{status}", e)
|
94
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