lite-command 3.0.1 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +0 -2
- data/CHANGELOG.md +8 -2
- data/Gemfile.lock +1 -1
- data/README.md +11 -5
- data/lib/lite/command/fault.rb +2 -7
- data/lib/lite/command/internals/executions.rb +2 -0
- data/lib/lite/command/internals/faults.rb +10 -0
- data/lib/lite/command/utils.rb +7 -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: 953b62c2ba61091b949e8fe3a673bc98be6a516afcea85192ea356e356aaf84e
|
4
|
+
data.tar.gz: adfb9bf29183586b33f8b32b801afadfbcf890398827e002dd794692bb708c9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b618d0bda8cdbdc2335a16900e00addbdcf0a71e4ee6170c907d3b1e8110415990191d4bc9a9b5a0765582d2ce83df758d4b9109114fa33f04ec0ca27e388524
|
7
|
+
data.tar.gz: 6a606bcd18ad5c97920e67557bc946f8e38446c83fdb2155a298530e338cf1f033e6388b411f7229919be6a70eb6c45510b8c1a1c95f9eeed0beabaa143550fa
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -6,9 +6,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
-
## [3.0
|
9
|
+
## [3.1.0] - 2024-10-25
|
10
10
|
### Added
|
11
|
-
- Added
|
11
|
+
- Added `raise!` method to reraise soft call errors
|
12
|
+
### Changed
|
13
|
+
- Fixed leakage of configuration option changes in spec
|
14
|
+
|
15
|
+
## [3.0.1] - 2024-10-25
|
16
|
+
### Changed
|
17
|
+
- Changed equality check for better matching
|
12
18
|
|
13
19
|
## [3.0.0] - 2024-10-15
|
14
20
|
### Added
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -88,15 +88,21 @@ end
|
|
88
88
|
|
89
89
|
Executing a command can be done as an instance or class call. It returns the command instance
|
90
90
|
in a frozen state. These will never call will never raise an execption, but will be kept track
|
91
|
-
of in its internal state.
|
91
|
+
of in its internal state. You can raise the offending exception using `raise!`.
|
92
92
|
|
93
93
|
```ruby
|
94
|
-
DecryptSecretMessage.call(...)
|
94
|
+
cmd = DecryptSecretMessage.call(...)
|
95
95
|
# - or -
|
96
|
-
DecryptSecretMessage.new(...).call
|
96
|
+
cmd = DecryptSecretMessage.new(...).call
|
97
97
|
|
98
|
-
# On success, fault
|
99
|
-
#=> <DecryptSecretMessage ...>
|
98
|
+
# On success, fault or exception:
|
99
|
+
cmd #=> <DecryptSecretMessage ...>
|
100
|
+
|
101
|
+
# On fault:
|
102
|
+
cmd.raise! #=> raises Lite::Command::Fault
|
103
|
+
|
104
|
+
# On exception:
|
105
|
+
cmd.raise! #=> raises StandardError
|
100
106
|
```
|
101
107
|
|
102
108
|
> [!TIP]
|
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
|
@@ -60,6 +60,7 @@ module Lite
|
|
60
60
|
around_execution { call }
|
61
61
|
Utils.try(self, :on_success)
|
62
62
|
rescue StandardError => e
|
63
|
+
@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
|
+
@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 :exception }
|
10
|
+
end
|
11
|
+
|
8
12
|
def caused_by
|
9
13
|
return if success?
|
10
14
|
|
@@ -29,6 +33,12 @@ module Lite
|
|
29
33
|
fault? && !caused_fault?
|
30
34
|
end
|
31
35
|
|
36
|
+
def raise!
|
37
|
+
return if exception.nil?
|
38
|
+
|
39
|
+
raise exception
|
40
|
+
end
|
41
|
+
|
32
42
|
private
|
33
43
|
|
34
44
|
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