lite-command 3.1.1 → 3.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6239fda55d099d36d3fc4c171ecf6eff2cd56bb5ffc4536dde420da339d0b5c9
4
- data.tar.gz: a7c3949c9313a479f16f4cf709730f8262576f4d899069240073c52923c9aac3
3
+ metadata.gz: 6eb09ff348ac355723d82848c69c1673d7ffa2782b3bb0061b16ccbe205b9529
4
+ data.tar.gz: 514ffc0ce29de277bd0969c29a51884d2509fd46b69e5cc6f85ded44fba4e827
5
5
  SHA512:
6
- metadata.gz: 6330c34c333948919685049c4eaefc5913ab364b09f28322ea6283aa73b3906715cc063b1b61192e231d5582206e0ae91be506fba09035317711dd56ad7f7ae2
7
- data.tar.gz: 69a682501448fb31fd0ad5709fc23f5f8b5dabc3c9a01486c4848a1d01f887523ab3fee3e7c2acdf6861b181bc1347dbee9bdccd6af3f1dc21321a6585a0a0f4
6
+ metadata.gz: 00d47aa6fc59fa96895311bd78be8dcf3b283da16197f6973eb5db4100b61ef6303ab65673b695dfd51cfbc64ae63eca9b70adc0eba46763a25597fa1c1e6ba0
7
+ data.tar.gz: 2e60eaa36e8b86cec861bc67bfa3bee12292c8edf8c92503e4339128f69f467421f94a4b53ee1a8a96a467cb25617cb6918d553419bbb6b1fbd23c817b2227dd
data/CHANGELOG.md CHANGED
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [3.1.2] - 2024-10-26
10
+ ### Changed
11
+ - Make state set methods private
12
+ - Add returns for invalid state and status transitions
13
+
9
14
  ## [3.1.1] - 2024-10-25
10
15
  ### Changed
11
16
  - 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.1)
4
+ lite-command (3.1.2)
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.1.0)
139
+ rubocop-rspec (3.2.0)
140
140
  rubocop (~> 1.61)
141
141
  ruby-progressbar (1.13.0)
142
142
  securerandom (0.3.1)
@@ -59,7 +59,7 @@ module Lite
59
59
  end
60
60
 
61
61
  def bad?(reason = nil)
62
- ![SUCCESS, NOOP].include?(status) && reason?(reason)
62
+ !ok?(reason)
63
63
  end
64
64
 
65
65
  FAULTS.each do |f|
@@ -75,22 +75,25 @@ module Lite
75
75
  str.nil? || str == reason
76
76
  end
77
77
 
78
- def fault(object, status, metadata)
79
- @status = status
80
- @metadata = metadata
78
+ def fault(object, s, m) # rubocop:disable Naming/MethodParameterName
79
+ return if s == SUCCESS || status != SUCCESS
81
80
 
82
- down_stream = Lite::Command::FaultStreamer.new(self, object)
83
- @reason ||= down_stream.reason
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
- @fault_exception ||= down_stream.fault_exception
84
+ fault_streamer = Lite::Command::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
+ @fault_exception ||= fault_streamer.fault_exception
89
90
  end
90
91
 
91
92
  FAULTS.each do |f|
92
93
  # eg: invalid!("idk") or failure!(fault) or error!("idk", { error_key: "some.error" })
93
94
  define_method(:"#{f}!") do |object, metadata = nil|
95
+ return unless success?
96
+
94
97
  fault(object, f, metadata)
95
98
  raise(fault_exception)
96
99
  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
@@ -61,7 +76,7 @@ module Lite
61
76
  Utils.try(self, :on_success)
62
77
  rescue StandardError => e
63
78
  @original_exception = e
64
- fault(e, ERROR, metadata) unless e.is_a?(Lite::Command::Fault)
79
+ fault(e, ERROR, metadata)
65
80
  after_execution
66
81
  Utils.try(self, :"on_#{status}", e)
67
82
  ensure
@@ -73,7 +88,7 @@ module Lite
73
88
  Utils.try(self, :on_success)
74
89
  rescue StandardError => e
75
90
  @original_exception = e
76
- fault(e, ERROR, metadata) unless e.is_a?(Lite::Command::Fault)
91
+ fault(e, ERROR, metadata)
77
92
  after_execution
78
93
  Utils.try(self, :"on_#{status}", e)
79
94
  raise(e)
@@ -35,7 +35,9 @@ module Lite
35
35
 
36
36
  def raise!(original: false)
37
37
  exception = (fault_exception unless original) || original_exception
38
- raise(exception) unless exception.nil?
38
+ return if exception.nil?
39
+
40
+ raise(exception)
39
41
  end
40
42
 
41
43
  private
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Command
5
5
 
6
- VERSION = "3.1.1"
6
+ VERSION = "3.1.2"
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.1.1
4
+ version: 3.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez