lite-command 3.2.1 → 3.3.0

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: e36dd86e0746fcaaa37f79e73a94b0ae406e1989c02105c6378c5f1ea8694165
4
- data.tar.gz: a10c6bda6ce19982ef9b983faa7ffa7ad3063ae8fc627229dc725238475c86c3
3
+ metadata.gz: 31f3a9216f2a7d081892c19b6e01cdd3a276583ccbe205950c8843621f9b4dcf
4
+ data.tar.gz: 4aca9ff7ac7e2d4ed7bcee96faa7605f71ccf37758034035a5fe3e6e26f38e7a
5
5
  SHA512:
6
- metadata.gz: f71e320cd7ec5b4c105900fd984c6f73fa30323ef734cf03b8b6333eebed459ac9c54234433864ce20b719ffa80eff6b3da9f4021257b965c7bc8380a3310518
7
- data.tar.gz: 78563217138c0d55133d344e914a9edb59cf9e59aaece25af3d1486657741151737d21f33a054821b80f26e3fd6bc92934e27bc3b9b3287cce969017284fa495
6
+ metadata.gz: e9f04fe907b9858f547ad748b86b5828456e077440f4a253c3d1c8fee61e2be9f452a6b77db7c8ebebacd623f57e6fda2d63c57f030041926691b5738619e250
7
+ data.tar.gz: a40de6560f56ab977c8e48e9a1ca2f3f16afbd6d7df59aa24df0239e23cfbc51b6f6a5d65d9aa6e879261e731562c5aba2d0ad95cac3ab55f6dde5789735cfb1
data/CHANGELOG.md CHANGED
@@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [3.3.0] - 2024-11-01
10
+ ### Changed
11
+ - Prefixed util method with `cmd_`
12
+ - Improve monotonic clock handling
13
+ - Improve order of hook calls
14
+
9
15
  ## [3.2.1] - 2024-10-29
10
16
  ### Changed
11
17
  - Allow if and unless evaluations to happen at the same time
data/Gemfile.lock CHANGED
@@ -1,16 +1,16 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lite-command (3.2.1)
4
+ lite-command (3.3.0)
5
5
  activemodel
6
6
  ostruct
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- actionpack (7.2.1.2)
12
- actionview (= 7.2.1.2)
13
- activesupport (= 7.2.1.2)
11
+ actionpack (7.2.2)
12
+ actionview (= 7.2.2)
13
+ activesupport (= 7.2.2)
14
14
  nokogiri (>= 1.8.5)
15
15
  racc
16
16
  rack (>= 2.2.4, < 3.2)
@@ -19,16 +19,17 @@ GEM
19
19
  rails-dom-testing (~> 2.2)
20
20
  rails-html-sanitizer (~> 1.6)
21
21
  useragent (~> 0.16)
22
- actionview (7.2.1.2)
23
- activesupport (= 7.2.1.2)
22
+ actionview (7.2.2)
23
+ activesupport (= 7.2.2)
24
24
  builder (~> 3.1)
25
25
  erubi (~> 1.11)
26
26
  rails-dom-testing (~> 2.2)
27
27
  rails-html-sanitizer (~> 1.6)
28
- activemodel (7.2.1.2)
29
- activesupport (= 7.2.1.2)
30
- activesupport (7.2.1.2)
28
+ activemodel (7.2.2)
29
+ activesupport (= 7.2.2)
30
+ activesupport (7.2.2)
31
31
  base64
32
+ benchmark (>= 0.3)
32
33
  bigdecimal
33
34
  concurrent-ruby (~> 1.0, >= 1.3.1)
34
35
  connection_pool (>= 2.2.5)
@@ -40,6 +41,7 @@ GEM
40
41
  tzinfo (~> 2.0, >= 2.0.5)
41
42
  ast (2.4.2)
42
43
  base64 (0.2.0)
44
+ benchmark (0.3.0)
43
45
  bigdecimal (3.1.8)
44
46
  builder (3.3.0)
45
47
  concurrent-ruby (1.3.4)
@@ -57,7 +59,7 @@ GEM
57
59
  irb (1.14.1)
58
60
  rdoc (>= 4.0.0)
59
61
  reline (>= 0.4.2)
60
- json (2.7.4)
62
+ json (2.7.5)
61
63
  language_server-protocol (3.17.0.3)
62
64
  logger (1.6.1)
63
65
  loofah (2.23.1)
@@ -70,7 +72,7 @@ GEM
70
72
  racc (~> 1.4)
71
73
  ostruct (0.6.0)
72
74
  parallel (1.26.3)
73
- parser (3.3.5.0)
75
+ parser (3.3.5.1)
74
76
  ast (~> 2.4.1)
75
77
  racc
76
78
  psych (5.1.2)
@@ -91,9 +93,9 @@ GEM
91
93
  rails-html-sanitizer (1.6.0)
92
94
  loofah (~> 2.21)
93
95
  nokogiri (~> 1.14)
94
- railties (7.2.1.2)
95
- actionpack (= 7.2.1.2)
96
- activesupport (= 7.2.1.2)
96
+ railties (7.2.2)
97
+ actionpack (= 7.2.2)
98
+ activesupport (= 7.2.2)
97
99
  irb (~> 1.13)
98
100
  rackup (>= 1.0.0)
99
101
  rake (>= 12.2)
@@ -119,7 +121,7 @@ GEM
119
121
  diff-lcs (>= 1.2.0, < 2.0)
120
122
  rspec-support (~> 3.13.0)
121
123
  rspec-support (3.13.1)
122
- rubocop (1.67.0)
124
+ rubocop (1.68.0)
123
125
  json (~> 2.3)
124
126
  language_server-protocol (>= 3.17.0)
125
127
  parallel (~> 1.10)
@@ -129,7 +131,7 @@ GEM
129
131
  rubocop-ast (>= 1.32.2, < 2.0)
130
132
  ruby-progressbar (~> 1.7)
131
133
  unicode-display_width (>= 2.4.0, < 3.0)
132
- rubocop-ast (1.32.3)
134
+ rubocop-ast (1.33.0)
133
135
  parser (>= 3.3.1.0)
134
136
  rubocop-performance (1.22.1)
135
137
  rubocop (>= 1.48.1, < 2.0)
@@ -140,7 +142,7 @@ GEM
140
142
  rubocop (~> 1.61)
141
143
  ruby-progressbar (1.13.0)
142
144
  securerandom (0.3.1)
143
- sqlite3 (2.1.1)
145
+ sqlite3 (2.2.0)
144
146
  mini_portile2 (~> 2.8.0)
145
147
  stringio (3.1.1)
146
148
  thor (1.3.2)
@@ -148,7 +150,7 @@ GEM
148
150
  concurrent-ruby (~> 1.0)
149
151
  unicode-display_width (2.6.0)
150
152
  useragent (0.16.10)
151
- webrick (1.8.2)
153
+ webrick (1.9.0)
152
154
  zeitwerk (2.7.1)
153
155
 
154
156
  PLATFORMS
data/README.md CHANGED
@@ -392,14 +392,13 @@ multiple times. Hooks are ran in the following order:
392
392
 
393
393
  ```ruby
394
394
  1. after_initialize
395
- 2. on_pending
395
+ 2. before_execution
396
396
  3. before_validation
397
397
  4. after_validation
398
- 5. before_execution
399
- 6. on_executing
400
- 7. after_execution
401
- 8. on_[success, noop, invalid, failure, error]
402
- 9. on_[complete, interrupted]
398
+ 5. on_executing
399
+ 6. on_[success, noop, invalid, failure, error]
400
+ 7. on_[complete, interrupted]
401
+ 8. after_execution
403
402
  ```
404
403
 
405
404
  ### Lifecycle Hooks
@@ -22,17 +22,17 @@ module Lite
22
22
  end
23
23
 
24
24
  def metadata
25
- Utils.try(object, :metadata) || command.metadata
25
+ Utils.cmd_try(object, :metadata) || command.metadata
26
26
  end
27
27
 
28
28
  def caused_by
29
- Utils.try(object, :caused_by) || command
29
+ Utils.cmd_try(object, :caused_by) || command
30
30
  end
31
31
 
32
32
  def thrown_by
33
- return object if Utils.try(object, :executed?)
33
+ return object if Utils.cmd_try(object, :executed?)
34
34
 
35
- Utils.try(object, :thrown_by) || command.caused_by
35
+ Utils.cmd_try(object, :thrown_by) || command.caused_by
36
36
  end
37
37
 
38
38
  def command_exception
@@ -36,7 +36,7 @@ module Lite
36
36
  define_method(method_name) do
37
37
  return unless respond_to?(from)
38
38
 
39
- Utils.try(send(from), method_name)
39
+ Utils.cmd_try(send(from), method_name)
40
40
  end
41
41
  end
42
42
  end
@@ -44,7 +44,7 @@ module Lite
44
44
  end
45
45
 
46
46
  def read_attribute_for_validation(method_name)
47
- Utils.try(self, method_name)
47
+ Utils.cmd_try(self, method_name)
48
48
  rescue NameError
49
49
  # Do nothing, fallback to :undefined error
50
50
  end
@@ -50,18 +50,19 @@ module Lite
50
50
  increment_execution_index
51
51
  assign_execution_cmd_id
52
52
  start_monotonic_time
53
- run_hooks(:on_pending)
54
- validate_context_attributes
53
+
55
54
  run_hooks(:before_execution)
56
55
  executing!
56
+ validate_context_attributes
57
57
  run_hooks(:on_executing)
58
58
  end
59
59
 
60
60
  def after_execution
61
61
  send(:"#{success? ? COMPLETE : INTERRUPTED}!")
62
- run_hooks(:after_execution)
63
62
  run_hooks(:"on_#{status}")
64
63
  run_hooks(:"on_#{state}")
64
+ run_hooks(:after_execution)
65
+
65
66
  stop_monotonic_time
66
67
  append_execution_result
67
68
  freeze_execution_objects
@@ -82,7 +83,7 @@ module Lite
82
83
  def execute!
83
84
  around_execution { call }
84
85
  rescue StandardError => e
85
- fault(e, Utils.try(e, :type) || ERROR, metadata, exception: e)
86
+ fault(e, Utils.cmd_try(e, :type) || ERROR, metadata, exception: e)
86
87
  after_execution
87
88
  raise(e)
88
89
  end
@@ -23,7 +23,7 @@ module Lite
23
23
  module ClassMethods
24
24
 
25
25
  def hooks
26
- @hooks ||= Utils.try(superclass, :hooks).dup || {}
26
+ @hooks ||= Utils.cmd_try(superclass, :hooks).dup || {}
27
27
  end
28
28
 
29
29
  HOOKS.each do |h|
@@ -41,7 +41,7 @@ module Lite
41
41
  hooks = self.class.hooks[hook]
42
42
  return if hooks.nil?
43
43
 
44
- hooks.each { |h| Utils.call(self, h) }
44
+ hooks.each { |h| Utils.cmd_call(self, h) }
45
45
  end
46
46
 
47
47
  end
@@ -34,6 +34,8 @@ module Lite
34
34
  end
35
35
 
36
36
  def runtime
37
+ return unless executed?
38
+
37
39
  stop_monotonic_time - start_monotonic_time
38
40
  end
39
41
 
@@ -12,7 +12,7 @@ module Lite
12
12
  end
13
13
 
14
14
  def run?(cmd)
15
- Utils.evaluate(cmd, options)
15
+ Utils.cmd_eval(cmd, options)
16
16
  end
17
17
 
18
18
  end
@@ -23,13 +23,13 @@ module Lite
23
23
  !!(object_class <= other_class)
24
24
  end
25
25
 
26
- def try(object, method_name, *args, include_private: true)
26
+ def cmd_try(object, method_name, *args, include_private: true)
27
27
  return unless object.respond_to?(method_name, include_private)
28
28
 
29
29
  object.send(method_name, *args)
30
30
  end
31
31
 
32
- def call(object, argument)
32
+ def cmd_call(object, argument)
33
33
  if argument.is_a?(Symbol) || argument.is_a?(String)
34
34
  object.send(argument)
35
35
  elsif argument.is_a?(Proc)
@@ -39,13 +39,13 @@ module Lite
39
39
  end
40
40
  end
41
41
 
42
- def evaluate(object, options = {})
42
+ def cmd_eval(object, options = {})
43
43
  if options[:if] && options[:unless]
44
- call(object, options[:if]) && !call(object, options[:unless])
44
+ cmd_call(object, options[:if]) && !cmd_call(object, options[:unless])
45
45
  elsif options[:if]
46
- call(object, options[:if])
46
+ cmd_call(object, options[:if])
47
47
  elsif options[:unless]
48
- !call(object, options[:unless])
48
+ !cmd_call(object, options[:unless])
49
49
  else
50
50
  options.fetch(:default, true)
51
51
  end
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Command
5
5
 
6
- VERSION = "3.2.1"
6
+ VERSION = "3.3.0"
7
7
 
8
8
  end
9
9
  end
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.2.1
4
+ version: 3.3.0
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-29 00:00:00.000000000 Z
11
+ date: 2024-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -229,7 +229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
229
229
  - !ruby/object:Gem::Version
230
230
  version: '0'
231
231
  requirements: []
232
- rubygems_version: 3.5.21
232
+ rubygems_version: 3.5.22
233
233
  signing_key:
234
234
  specification_version: 4
235
235
  summary: Ruby Command based framework (aka service objects)