lite-command 3.1.3 → 3.1.4

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: 39377d9ecb58d9d61ae0c99305d9db08672b7f97eb368194fc209b419cec1d0a
4
- data.tar.gz: 5ec36c8fcb1d68e2a6bd3ae0866f687a9c04469d502dcba0bc7fe092a9b88351
3
+ metadata.gz: d88e18025d91c08352d81be6288346138b4c07f8c6c1b7e437c1309f4c4ed330
4
+ data.tar.gz: 1011eca8e0ca7854dfd9b488d8f91a467d15ff2dccc60f5a36eb433ef3761fe7
5
5
  SHA512:
6
- metadata.gz: 521be42ef9eab72ca99c2cd8dfba53ca3156538daf1e7715aff5123aefc6a70d7c4b439962306b8d1d22b87897bed1f54167353f98bea32d83ebf5eaaceffefe
7
- data.tar.gz: 6c33d9b29e925c30b2e5abe06088fcfb0bccbd9cedbd241d76f398a89cfb7a679bf2a59b86ae766ccec69d94496640613d39995e9eca35ac3938d165a8e96eed
6
+ metadata.gz: 42eb9126777ee23506f1d98c3313e6de9c03da120b6711a399ad99051c88faac769080e4f41891c3a2658381aa4ad93eaf191c4ec00e446c8507f5f5ca8108fe
7
+ data.tar.gz: f314544be97beead7f55e6e8ee3f164e9a80013368aaa1380f632e0a702dd3fecb555a06d9e100990454aff6249a01a35c688a28792aa9b1e7351e624e38b542
data/CHANGELOG.md CHANGED
@@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [3.1.4] - 2024-10-27
10
+ ### Added
11
+ - Add exception data to results hash
12
+ ### Changed
13
+ - Relocated some results methods to a runtimes internal module
14
+ - Assign correct fault even when child command is hard called
15
+ - Renamed `fault_exception` to `command_exception`
16
+
9
17
  ## [3.1.3] - 2024-10-26
10
18
  ### Added
11
19
  - Added passing `original_exception` to fault `!` calls
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lite-command (3.1.3)
4
+ lite-command (3.1.4)
5
5
  activemodel
6
6
  ostruct
7
7
 
@@ -11,10 +11,11 @@ module Lite
11
11
 
12
12
  base.include ActiveModel::Validations
13
13
 
14
+ base.include Internals::Runtimes
14
15
  base.include Internals::Attributes
16
+ base.include Internals::Faults
15
17
  base.include Internals::Calls
16
18
  base.include Internals::Executions
17
- base.include Internals::Faults
18
19
  base.include Internals::Results
19
20
 
20
21
  if Lite::Command.configuration.raise_dynamic_faults # rubocop:disable Style/GuardClause
@@ -15,7 +15,7 @@ module Lite
15
15
  if object.respond_to?(:reason)
16
16
  object.reason
17
17
  elsif object.is_a?(StandardError)
18
- "[#{object.class.name}] #{object.message}".chomp(".")
18
+ Utils.pretty_exception(object)
19
19
  else
20
20
  object
21
21
  end
@@ -35,7 +35,7 @@ module Lite
35
35
  Utils.try(object, :thrown_by) || command.caused_by
36
36
  end
37
37
 
38
- def fault_exception
38
+ def command_exception
39
39
  return if command.success?
40
40
 
41
41
  Fault.build(
@@ -75,7 +75,7 @@ module Lite
75
75
  str.nil? || str == reason
76
76
  end
77
77
 
78
- def fault(object, s, m, oe) # rubocop:disable Naming/MethodParameterName
78
+ def fault(object, s, m, exception: nil) # rubocop:disable Naming/MethodParameterName
79
79
  return if s == SUCCESS || status != SUCCESS
80
80
 
81
81
  @status = s
@@ -87,8 +87,8 @@ module Lite
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
+ @command_exception ||= fault_streamer.command_exception
91
+ @original_exception ||= exception || command_exception
92
92
  end
93
93
 
94
94
  FAULTS.each do |f|
@@ -96,9 +96,9 @@ module Lite
96
96
  define_method(:"#{f}!") do |object, metadata: nil, original_exception: nil|
97
97
  return unless success?
98
98
 
99
- fault(object, f, metadata, original_exception)
99
+ fault(object, f, metadata, exception: original_exception)
100
100
 
101
- raise(fault_exception)
101
+ raise(command_exception)
102
102
  end
103
103
  end
104
104
 
@@ -75,7 +75,7 @@ module Lite
75
75
  around_execution { call }
76
76
  Utils.try(self, :on_success)
77
77
  rescue StandardError => e
78
- fault(e, ERROR, metadata, e)
78
+ fault(e, Utils.try(e, :type) || ERROR, metadata, exception: e)
79
79
  after_execution
80
80
  Utils.try(self, :"on_#{status}", e)
81
81
  ensure
@@ -86,7 +86,7 @@ module Lite
86
86
  around_execution { call }
87
87
  Utils.try(self, :on_success)
88
88
  rescue StandardError => e
89
- fault(e, ERROR, metadata, e)
89
+ fault(e, Utils.try(e, :type) || ERROR, metadata, exception: e)
90
90
  after_execution
91
91
  Utils.try(self, :"on_#{status}", e)
92
92
  raise(e)
@@ -6,7 +6,7 @@ module Lite
6
6
  module Faults
7
7
 
8
8
  def self.included(base)
9
- base.class_eval { attr_reader :fault_exception, :original_exception }
9
+ base.class_eval { attr_reader :command_exception, :original_exception }
10
10
  end
11
11
 
12
12
  def caused_by
@@ -34,7 +34,7 @@ module Lite
34
34
  end
35
35
 
36
36
  def raise!(original: false)
37
- exception = (fault_exception unless original) || original_exception
37
+ exception = (command_exception unless original) || original_exception
38
38
  return if exception.nil?
39
39
 
40
40
  raise(exception)
@@ -1,20 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "securerandom" unless defined?(SecureRandom)
4
-
5
3
  module Lite
6
4
  module Command
7
5
  module Internals
8
6
  module Results
9
7
 
10
- def index
11
- @index ||= context.index ||= 0
12
- end
13
-
14
- def cmd_id
15
- @cmd_id ||= context.cmd_id ||= SecureRandom.uuid
16
- end
17
-
18
8
  def outcome
19
9
  return state if pending? || thrown?
20
10
 
@@ -36,7 +26,9 @@ module Lite
36
26
  reason:,
37
27
  metadata:,
38
28
  caused_by: caused_by&.index,
29
+ caused_exception: Utils.pretty_exception(caused_by&.original_exception),
39
30
  thrown_by: thrown_by&.index,
31
+ thrown_exception: Utils.pretty_exception(thrown_by&.command_exception),
40
32
  runtime:
41
33
  }.compact
42
34
  end
@@ -44,26 +36,6 @@ module Lite
44
36
 
45
37
  private
46
38
 
47
- def assign_execution_cmd_id
48
- @cmd_id = context.cmd_id ||= cmd_id
49
- end
50
-
51
- def increment_execution_index
52
- @index = context.index = index.next
53
- end
54
-
55
- def start_monotonic_time
56
- @start_monotonic_time ||= Utils.monotonic_time
57
- end
58
-
59
- def stop_monotonic_time
60
- @stop_monotonic_time ||= Utils.monotonic_time
61
- end
62
-
63
- def runtime
64
- stop_monotonic_time - start_monotonic_time
65
- end
66
-
67
39
  def append_execution_result
68
40
  results.push(self).sort_by!(&:index)
69
41
  end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "securerandom" unless defined?(SecureRandom)
4
+
5
+ module Lite
6
+ module Command
7
+ module Internals
8
+ module Runtimes
9
+
10
+ def index
11
+ @index ||= context.index ||= 0
12
+ end
13
+
14
+ def cmd_id
15
+ @cmd_id ||= context.cmd_id ||= SecureRandom.uuid
16
+ end
17
+
18
+ private
19
+
20
+ def assign_execution_cmd_id
21
+ @cmd_id = context.cmd_id ||= cmd_id
22
+ end
23
+
24
+ def increment_execution_index
25
+ @index = context.index = index.next
26
+ end
27
+
28
+ def start_monotonic_time
29
+ @start_monotonic_time ||= Utils.monotonic_time
30
+ end
31
+
32
+ def stop_monotonic_time
33
+ @stop_monotonic_time ||= Utils.monotonic_time
34
+ end
35
+
36
+ def runtime
37
+ stop_monotonic_time - start_monotonic_time
38
+ end
39
+
40
+ end
41
+ end
42
+ end
43
+ end
@@ -10,6 +10,12 @@ module Lite
10
10
  Process.clock_gettime(Process::CLOCK_MONOTONIC)
11
11
  end
12
12
 
13
+ def pretty_exception(exception)
14
+ return if exception.nil?
15
+
16
+ "[#{exception.class.name}] #{exception.message}".chomp(".")
17
+ end
18
+
13
19
  def descendant_of?(object, other)
14
20
  object_class = object.respond_to?(:new) ? object : object.class
15
21
  other_class = other.respond_to?(:new) ? other : other.class
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Command
5
5
 
6
- VERSION = "3.1.3"
6
+ VERSION = "3.1.4"
7
7
 
8
8
  end
9
9
  end
data/lib/lite/command.rb CHANGED
@@ -11,10 +11,11 @@ require "lite/command/utils"
11
11
  require "lite/command/context"
12
12
  require "lite/command/fault"
13
13
  require "lite/command/fault_streamer"
14
+ require "lite/command/internals/runtimes"
14
15
  require "lite/command/internals/attributes"
16
+ require "lite/command/internals/faults"
15
17
  require "lite/command/internals/calls"
16
18
  require "lite/command/internals/executions"
17
- require "lite/command/internals/faults"
18
19
  require "lite/command/internals/results"
19
20
  require "lite/command/base"
20
21
  require "lite/command/step"
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.1.3
4
+ version: 3.1.4
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-26 00:00:00.000000000 Z
11
+ date: 2024-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -202,6 +202,7 @@ files:
202
202
  - lib/lite/command/internals/executions.rb
203
203
  - lib/lite/command/internals/faults.rb
204
204
  - lib/lite/command/internals/results.rb
205
+ - lib/lite/command/internals/runtimes.rb
205
206
  - lib/lite/command/sequence.rb
206
207
  - lib/lite/command/step.rb
207
208
  - lib/lite/command/utils.rb