async-service 0.14.2 → 0.14.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: d183945602c8bb4ac0408390671c73a0e7b86baae548194a91ce0587f6d5941a
4
- data.tar.gz: 2dbb203184966a7abffaa996c80ec82e1664cd952f4b37997553797396145289
3
+ metadata.gz: '09520c2c06a66a0524f733e446046f67e24d8a316ba4d08e566863dae765116d'
4
+ data.tar.gz: 8462198e099679b85c524d75a15ca8911ab17d31da71e492dbeda2958006a752
5
5
  SHA512:
6
- metadata.gz: 965863a04ce7cee71764485e7adce9be13324ccf5a8fe8ee04df2e831c9137bdff8bc47d4b62b637db5d98661918df46affb8ef29003899a0f23bb44920c5ca2
7
- data.tar.gz: 56a49adffb4902fc4ac4dc9b8638e1ce21f214e172de610a28f4c448a29002499d0535b077828098e9b19415af18184866612103765043796c4c61d85ce4614f
6
+ metadata.gz: 39579c924d04afb7271183498a40ab91f7380f1d848dd52c5785f49823ec85d19f173ecd9cf09de92229c4b9e80a5f22dadd7f4eed5663ea1a356ad8f12534c9
7
+ data.tar.gz: 17bf024007654e733965b103747f72db73f5dd89484c000320dee4296426321ce92cb0ed30f1f7a45d65992aaf6269c9111c0ddcdb51bfdbe1bec0dfeb8c30c5
checksums.yaml.gz.sig CHANGED
Binary file
@@ -3,6 +3,8 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2025, by Samuel Williams.
5
5
 
6
+ require "string/format"
7
+
6
8
  module Async
7
9
  module Service
8
10
  # Formatting utilities for service titles.
@@ -10,33 +12,15 @@ module Async
10
12
  # Services need meaningful process/thread names for monitoring and debugging. This module provides consistent formatting for common service metrics like connection counts, request ratios, and load values in process titles.
11
13
  #
12
14
  # It is expected you will include these into your service class and use them to update the `instance.name` in the health check.
15
+ #
16
+ # @deprecated Use {String::Format} directly.
13
17
  module Formatting
14
- UNITS = [nil, "K", "M", "B", "T", "P", "E", "Z", "Y"]
15
-
16
18
  # Format a count into a human-readable string.
17
19
  # @parameter value [Numeric] The count to format.
18
- # @parameter units [Array] The units to use for formatting (default: UNITS).
20
+ # @parameter units [Array] The units to use for formatting (default: String::Format::UNITS).
19
21
  # @returns [String] A formatted string representing the count.
20
- def format_count(value, units = UNITS)
21
- value = value
22
- index = 0
23
- limit = units.size - 1
24
-
25
- # Handle negative numbers by working with absolute value:
26
- negative = value < 0
27
- value = value.abs
28
-
29
- while value >= 1000 and index < limit
30
- value = value / 1000.0
31
- index += 1
32
- end
33
-
34
- result = String.new
35
- result << "-" if negative
36
- result << value.round(2).to_s
37
- result << units[index].to_s if units[index]
38
-
39
- return result
22
+ def format_count(value, units = String::Format::UNITS)
23
+ String::Format.count(value, units)
40
24
  end
41
25
 
42
26
  module_function :format_count
@@ -46,7 +30,7 @@ module Async
46
30
  # @parameter total [Numeric] The total value.
47
31
  # @returns [String] A formatted ratio string.
48
32
  def format_ratio(current, total)
49
- "#{format_count(current)}/#{format_count(total)}"
33
+ String::Format.ratio(current, total)
50
34
  end
51
35
 
52
36
  module_function :format_ratio
@@ -55,27 +39,16 @@ module Async
55
39
  # @parameter load [Numeric] The load value (typically 0.0 to 1.0+).
56
40
  # @returns [String] A formatted load string.
57
41
  def format_load(load)
58
- load.round(2).to_s
42
+ String::Format.decimal(load)
59
43
  end
60
44
 
61
45
  module_function :format_load
62
46
 
63
47
  # Format multiple statistics into a compact string.
64
- # @parameter stats [Hash] Hash of statistic names to values or [current, total] arrays.
48
+ # @parameter pairs [Hash] Hash of statistic names to values or [current, total] arrays.
65
49
  # @returns [String] A formatted statistics string.
66
50
  def format_statistics(**pairs)
67
- pairs.map do |key, value|
68
- case value
69
- when Array
70
- if value.length == 2
71
- "#{key.to_s.upcase}=#{format_ratio(value[0], value[1])}"
72
- else
73
- "#{key.to_s.upcase}=#{value.join('/')}"
74
- end
75
- else
76
- "#{key.to_s.upcase}=#{format_count(value)}"
77
- end
78
- end.join(" ")
51
+ String::Format.statistics(pairs)
79
52
  end
80
53
 
81
54
  module_function :format_statistics
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Async
7
7
  module Service
8
- VERSION = "0.14.2"
8
+ VERSION = "0.14.4"
9
9
  end
10
10
  end
data/readme.md CHANGED
@@ -27,6 +27,10 @@ Please see the [project documentation](https://socketry.github.io/async-service/
27
27
 
28
28
  Please see the [project releases](https://socketry.github.io/async-service/releases/index) for all releases.
29
29
 
30
+ ### v0.14.4
31
+
32
+ - Use `String::Format` gem for formatting.
33
+
30
34
  ### v0.14.0
31
35
 
32
36
  - Introduce `ContainerEnvironment` and `ContainerService` for implementing best-practice services.
@@ -67,10 +71,6 @@ Please see the [project releases](https://socketry.github.io/async-service/relea
67
71
 
68
72
  - Fix requirement that facet must be a module.
69
73
 
70
- ### v0.6.0
71
-
72
- - Unify construction of environments for better consistency.
73
-
74
74
  ## Contributing
75
75
 
76
76
  We welcome contributions to this project.
data/releases.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Releases
2
2
 
3
+ ## v0.14.4
4
+
5
+ - Use `String::Format` gem for formatting.
6
+
3
7
  ## v0.14.0
4
8
 
5
9
  - Introduce `ContainerEnvironment` and `ContainerService` for implementing best-practice services.
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.2
4
+ version: 0.14.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.16'
69
+ - !ruby/object:Gem::Dependency
70
+ name: string-format
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.2'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.2'
69
83
  executables:
70
84
  - async-service
71
85
  extensions: []
metadata.gz.sig CHANGED
Binary file