lite-command 3.2.1 → 3.3.1

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: 715ff5866aa3e438fe2da7a110146697ba7cb096e6e971fd433b43004e950767
4
+ data.tar.gz: 896ab3c6aeca65820801d76669034635d2b71e46272a7ac568cd9998e378ca12
5
5
  SHA512:
6
- metadata.gz: f71e320cd7ec5b4c105900fd984c6f73fa30323ef734cf03b8b6333eebed459ac9c54234433864ce20b719ffa80eff6b3da9f4021257b965c7bc8380a3310518
7
- data.tar.gz: 78563217138c0d55133d344e914a9edb59cf9e59aaece25af3d1486657741151737d21f33a054821b80f26e3fd6bc92934e27bc3b9b3287cce969017284fa495
6
+ metadata.gz: f82235ae25a48c0662a3948a8fd3c5e06605a76b284bcabfea32aad3df5efa36cb48778ec3ced570dd14bb05433c76c7fd9aa71df2e96004f258fed8fd27632f
7
+ data.tar.gz: 01475342f8fe446f4ed69a7a4114fd7924a08fb96f3e659c3d65d332ff28c5c1fd4376a4c9dddd72f38074fb708252d9459bea11d913f9ef4d284edffd227f12
data/CHANGELOG.md CHANGED
@@ -6,6 +6,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [3.3.1] - 2024-11-06
10
+ ### Removed
11
+ - Remove `to_hash` method
12
+
13
+ ## [3.3.0] - 2024-11-01
14
+ ### Changed
15
+ - Prefixed util method with `cmd_`
16
+ - Improve monotonic clock handling
17
+ - Improve order of hook calls
18
+
9
19
  ## [3.2.1] - 2024-10-29
10
20
  ### Changed
11
21
  - 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.1)
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.8.0)
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.6.0)
74
76
  ast (~> 2.4.1)
75
77
  racc
76
78
  psych (5.1.2)
@@ -81,9 +83,8 @@ GEM
81
83
  rack (>= 3.0.0)
82
84
  rack-test (2.1.0)
83
85
  rack (>= 1.3)
84
- rackup (2.1.0)
86
+ rackup (2.2.0)
85
87
  rack (>= 3)
86
- webrick (~> 1.8)
87
88
  rails-dom-testing (2.2.0)
88
89
  activesupport (>= 5.0.0)
89
90
  minitest
@@ -91,9 +92,9 @@ GEM
91
92
  rails-html-sanitizer (1.6.0)
92
93
  loofah (~> 2.21)
93
94
  nokogiri (~> 1.14)
94
- railties (7.2.1.2)
95
- actionpack (= 7.2.1.2)
96
- activesupport (= 7.2.1.2)
95
+ railties (7.2.2)
96
+ actionpack (= 7.2.2)
97
+ activesupport (= 7.2.2)
97
98
  irb (~> 1.13)
98
99
  rackup (>= 1.0.0)
99
100
  rake (>= 12.2)
@@ -119,7 +120,7 @@ GEM
119
120
  diff-lcs (>= 1.2.0, < 2.0)
120
121
  rspec-support (~> 3.13.0)
121
122
  rspec-support (3.13.1)
122
- rubocop (1.67.0)
123
+ rubocop (1.68.0)
123
124
  json (~> 2.3)
124
125
  language_server-protocol (>= 3.17.0)
125
126
  parallel (~> 1.10)
@@ -129,7 +130,7 @@ GEM
129
130
  rubocop-ast (>= 1.32.2, < 2.0)
130
131
  ruby-progressbar (~> 1.7)
131
132
  unicode-display_width (>= 2.4.0, < 3.0)
132
- rubocop-ast (1.32.3)
133
+ rubocop-ast (1.34.0)
133
134
  parser (>= 3.3.1.0)
134
135
  rubocop-performance (1.22.1)
135
136
  rubocop (>= 1.48.1, < 2.0)
@@ -140,7 +141,7 @@ GEM
140
141
  rubocop (~> 1.61)
141
142
  ruby-progressbar (1.13.0)
142
143
  securerandom (0.3.1)
143
- sqlite3 (2.1.1)
144
+ sqlite3 (2.2.0)
144
145
  mini_portile2 (~> 2.8.0)
145
146
  stringio (3.1.1)
146
147
  thor (1.3.2)
@@ -148,7 +149,6 @@ GEM
148
149
  concurrent-ruby (~> 1.0)
149
150
  unicode-display_width (2.6.0)
150
151
  useragent (0.16.10)
151
- webrick (1.8.2)
152
152
  zeitwerk (2.7.1)
153
153
 
154
154
  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
@@ -15,7 +15,7 @@ module Lite
15
15
  @results ||= context.results ||= []
16
16
  end
17
17
 
18
- def to_hash
18
+ def to_h
19
19
  {
20
20
  index:,
21
21
  cmd_id:,
@@ -32,7 +32,6 @@ module Lite
32
32
  runtime:
33
33
  }.compact
34
34
  end
35
- alias to_h to_hash
36
35
 
37
36
  private
38
37
 
@@ -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.1"
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.1
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-06 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)