lite-command 3.0.1 → 3.1.1
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/.rubocop.yml +0 -2
- data/CHANGELOG.md +12 -2
- data/Gemfile.lock +1 -1
- data/README.md +25 -1
- data/lib/lite/command/fault.rb +2 -7
- data/lib/lite/command/fault_streamer.rb +22 -11
- data/lib/lite/command/internals/calls.rb +3 -1
- data/lib/lite/command/internals/executions.rb +2 -0
- data/lib/lite/command/internals/faults.rb +9 -0
- data/lib/lite/command/utils.rb +7 -0
- data/lib/lite/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: 6239fda55d099d36d3fc4c171ecf6eff2cd56bb5ffc4536dde420da339d0b5c9
|
4
|
+
data.tar.gz: a7c3949c9313a479f16f4cf709730f8262576f4d899069240073c52923c9aac3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6330c34c333948919685049c4eaefc5913ab364b09f28322ea6283aa73b3906715cc063b1b61192e231d5582206e0ae91be506fba09035317711dd56ad7f7ae2
|
7
|
+
data.tar.gz: 69a682501448fb31fd0ad5709fc23f5f8b5dabc3c9a01486c4848a1d01f887523ab3fee3e7c2acdf6861b181bc1347dbee9bdccd6af3f1dc21321a6585a0a0f4
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -6,9 +6,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
-
## [3.
|
9
|
+
## [3.1.1] - 2024-10-25
|
10
|
+
### Changed
|
11
|
+
- Add option to raise original or fault exception
|
12
|
+
|
13
|
+
## [3.1.0] - 2024-10-25
|
10
14
|
### Added
|
11
|
-
- Added
|
15
|
+
- Added `raise!` method to reraise soft call errors
|
16
|
+
### Changed
|
17
|
+
- Fixed leakage of configuration option changes in spec
|
18
|
+
|
19
|
+
## [3.0.1] - 2024-10-25
|
20
|
+
### Changed
|
21
|
+
- Changed equality check for better matching
|
12
22
|
|
13
23
|
## [3.0.0] - 2024-10-15
|
14
24
|
### Added
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -26,6 +26,7 @@ Or install it yourself as:
|
|
26
26
|
* [Usage](#usage)
|
27
27
|
* [Execution](#execution)
|
28
28
|
* [Dynamic Faults](#dynamic-faults)
|
29
|
+
* [Raising Faults](#raising-faults)
|
29
30
|
* [Context](#context)
|
30
31
|
* [Attributes](#attributes)
|
31
32
|
* [Validations](#validations)
|
@@ -95,7 +96,7 @@ DecryptSecretMessage.call(...)
|
|
95
96
|
# - or -
|
96
97
|
DecryptSecretMessage.new(...).call
|
97
98
|
|
98
|
-
# On success, fault
|
99
|
+
# On success, fault or exception:
|
99
100
|
#=> <DecryptSecretMessage ...>
|
100
101
|
```
|
101
102
|
|
@@ -121,6 +122,29 @@ DecryptSecretMessage.new(...).call!
|
|
121
122
|
#=> raises StandardError
|
122
123
|
```
|
123
124
|
|
125
|
+
### Raising Faults
|
126
|
+
|
127
|
+
Sometimes its suitable to raise the offending soft call command fault later
|
128
|
+
in a call stack. Use the `raise!` method to reraise the fault or original
|
129
|
+
error (if they differ). `original: false` is the default.
|
130
|
+
|
131
|
+
```ruby
|
132
|
+
cmd = DecryptSecretMessage.call(...)
|
133
|
+
Apm.track_stat("DecryptSecretMessage.called")
|
134
|
+
# other stuff...
|
135
|
+
|
136
|
+
# On success:
|
137
|
+
cmd.raise! #=> nil
|
138
|
+
|
139
|
+
# On fault:
|
140
|
+
cmd.raise!(original: false) #=> raises Lite::Command::Fault
|
141
|
+
cmd.raise!(original: true) #=> raises Lite::Command::Fault
|
142
|
+
|
143
|
+
# On exception:
|
144
|
+
cmd.raise!(original: false) #=> raises Lite::Command::Error
|
145
|
+
cmd.raise!(original: true) #=> raises StandardError
|
146
|
+
```
|
147
|
+
|
124
148
|
### Dynamic Faults
|
125
149
|
|
126
150
|
Dynamic faults are custom faults named after your command. This is especially
|
data/lib/lite/command/fault.rb
CHANGED
@@ -30,11 +30,7 @@ module Lite
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def self.===(item)
|
33
|
-
|
34
|
-
klass1 = item.respond_to?(:new) ? item : item.class
|
35
|
-
return true if klass0 == klass1
|
36
|
-
|
37
|
-
klass0.ancestors.include?(klass1) || klass1.ancestors.include?(klass0)
|
33
|
+
Utils.descendant_of?(self, item) || Utils.descendant_of?(item, self)
|
38
34
|
end
|
39
35
|
|
40
36
|
def type
|
@@ -42,8 +38,7 @@ module Lite
|
|
42
38
|
end
|
43
39
|
|
44
40
|
def ===(item)
|
45
|
-
|
46
|
-
is_a?(klass)
|
41
|
+
Utils.descendant_of?(self, item)
|
47
42
|
end
|
48
43
|
|
49
44
|
end
|
@@ -11,6 +11,20 @@ module Lite
|
|
11
11
|
@object = object
|
12
12
|
end
|
13
13
|
|
14
|
+
def reason
|
15
|
+
if object.respond_to?(:reason)
|
16
|
+
object.reason
|
17
|
+
elsif object.is_a?(StandardError)
|
18
|
+
"[#{object.class.name}] #{object.message}".chomp(".")
|
19
|
+
else
|
20
|
+
object
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def metadata
|
25
|
+
Utils.try(object, :metadata) || command.metadata
|
26
|
+
end
|
27
|
+
|
14
28
|
def caused_by
|
15
29
|
Utils.try(object, :caused_by) || command
|
16
30
|
end
|
@@ -21,18 +35,15 @@ module Lite
|
|
21
35
|
Utils.try(object, :thrown_by) || command.caused_by
|
22
36
|
end
|
23
37
|
|
24
|
-
def
|
25
|
-
|
26
|
-
end
|
38
|
+
def fault_exception
|
39
|
+
return if command.success?
|
27
40
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
object
|
35
|
-
end
|
41
|
+
Fault.build(
|
42
|
+
command.status.capitalize,
|
43
|
+
command,
|
44
|
+
object,
|
45
|
+
dynamic: command.send(:raise_dynamic_faults?)
|
46
|
+
)
|
36
47
|
end
|
37
48
|
|
38
49
|
end
|
@@ -84,13 +84,15 @@ module Lite
|
|
84
84
|
@metadata ||= down_stream.metadata
|
85
85
|
@caused_by ||= down_stream.caused_by
|
86
86
|
@thrown_by ||= down_stream.thrown_by
|
87
|
+
|
88
|
+
@fault_exception ||= down_stream.fault_exception
|
87
89
|
end
|
88
90
|
|
89
91
|
FAULTS.each do |f|
|
90
92
|
# eg: invalid!("idk") or failure!(fault) or error!("idk", { error_key: "some.error" })
|
91
93
|
define_method(:"#{f}!") do |object, metadata = nil|
|
92
94
|
fault(object, f, metadata)
|
93
|
-
raise
|
95
|
+
raise(fault_exception)
|
94
96
|
end
|
95
97
|
end
|
96
98
|
|
@@ -60,6 +60,7 @@ module Lite
|
|
60
60
|
around_execution { call }
|
61
61
|
Utils.try(self, :on_success)
|
62
62
|
rescue StandardError => e
|
63
|
+
@original_exception = e
|
63
64
|
fault(e, ERROR, metadata) unless e.is_a?(Lite::Command::Fault)
|
64
65
|
after_execution
|
65
66
|
Utils.try(self, :"on_#{status}", e)
|
@@ -71,6 +72,7 @@ module Lite
|
|
71
72
|
around_execution { call }
|
72
73
|
Utils.try(self, :on_success)
|
73
74
|
rescue StandardError => e
|
75
|
+
@original_exception = e
|
74
76
|
fault(e, ERROR, metadata) unless e.is_a?(Lite::Command::Fault)
|
75
77
|
after_execution
|
76
78
|
Utils.try(self, :"on_#{status}", e)
|
@@ -5,6 +5,10 @@ module Lite
|
|
5
5
|
module Internals
|
6
6
|
module Faults
|
7
7
|
|
8
|
+
def self.included(base)
|
9
|
+
base.class_eval { attr_reader :fault_exception, :original_exception }
|
10
|
+
end
|
11
|
+
|
8
12
|
def caused_by
|
9
13
|
return if success?
|
10
14
|
|
@@ -29,6 +33,11 @@ module Lite
|
|
29
33
|
fault? && !caused_fault?
|
30
34
|
end
|
31
35
|
|
36
|
+
def raise!(original: false)
|
37
|
+
exception = (fault_exception unless original) || original_exception
|
38
|
+
raise(exception) unless exception.nil?
|
39
|
+
end
|
40
|
+
|
32
41
|
private
|
33
42
|
|
34
43
|
def throw!(command)
|
data/lib/lite/command/utils.rb
CHANGED
@@ -6,6 +6,13 @@ module Lite
|
|
6
6
|
|
7
7
|
module_function
|
8
8
|
|
9
|
+
def descendant_of?(object, other)
|
10
|
+
object_class = object.respond_to?(:new) ? object : object.class
|
11
|
+
other_class = other.respond_to?(:new) ? other : other.class
|
12
|
+
|
13
|
+
!!(object_class <= other_class)
|
14
|
+
end
|
15
|
+
|
9
16
|
def try(object, method_name, *args, include_private: true)
|
10
17
|
return unless object.respond_to?(method_name, include_private)
|
11
18
|
|
data/lib/lite/command/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lite-command
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Gomez
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|