lite-command 3.0.1 → 3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ca95adc16c60158c9a6b826dc9b87f826dc0a81574fd85b996147bbc9ba7c7f2
4
- data.tar.gz: 26d5c68abb7572aa5c887f324fe138c4eb282eb00308dcda83059ace331d2c1b
3
+ metadata.gz: 953b62c2ba61091b949e8fe3a673bc98be6a516afcea85192ea356e356aaf84e
4
+ data.tar.gz: adfb9bf29183586b33f8b32b801afadfbcf890398827e002dd794692bb708c9e
5
5
  SHA512:
6
- metadata.gz: 73217979c23fff74cf8a9f4965627e3c69bb3d6b74b3b815cb70af3ad766a4ecd412acfb11e96dfc777427eca9dd113c1782e0e407838836d165e1f716f0e241
7
- data.tar.gz: ec3f313e195d97d5c22f8187d78dc0b328288eaa4f2c57de72edce22949b4c75825f63842df7a8141059161efefb1ab45f6457c2b47d2e33efe6fa136b8e7ed7
6
+ metadata.gz: b618d0bda8cdbdc2335a16900e00addbdcf0a71e4ee6170c907d3b1e8110415990191d4bc9a9b5a0765582d2ce83df758d4b9109114fa33f04ec0ca27e388524
7
+ data.tar.gz: 6a606bcd18ad5c97920e67557bc946f8e38446c83fdb2155a298530e338cf1f033e6388b411f7229919be6a70eb6c45510b8c1a1c95f9eeed0beabaa143550fa
data/.rubocop.yml CHANGED
@@ -42,8 +42,6 @@ Metrics/PerceivedComplexity:
42
42
  Enabled: false
43
43
  Naming/MemoizedInstanceVariableName:
44
44
  Enabled: false
45
- Performance/AncestorsInclude:
46
- Enabled: false
47
45
  RSpec/AnyInstance:
48
46
  Enabled: false
49
47
  RSpec/DescribedClass:
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.1] - 2024-10-25
9
+ ## [3.1.0] - 2024-10-25
10
10
  ### Added
11
- - Added improved equality check
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lite-command (3.0.1)
4
+ lite-command (3.1.0)
5
5
  activemodel
6
6
  ostruct
7
7
 
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 and exception:
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]
@@ -30,11 +30,7 @@ module Lite
30
30
  end
31
31
 
32
32
  def self.===(item)
33
- klass0 = respond_to?(:new) ? self : self.class
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
- klass = item.respond_to?(:new) ? item : item.class
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)
@@ -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
 
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Command
5
5
 
6
- VERSION = "3.0.1"
6
+ VERSION = "3.1.0"
7
7
 
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lite-command
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez