utils 0.80.0 → 0.82.0

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: 74d1c4048d40164e89c4edcd2b3bd91516b0bf82d6f8d0b0d68c25b70c21927e
4
- data.tar.gz: 290d49a38bd95423c93f0c5df749ada24245731369c9233d11f3de619f5099d6
3
+ metadata.gz: 3e7a6c6bc8c38c84587412e072fa0ddee7e9e854a61eb50b4caded051d1388b7
4
+ data.tar.gz: b6e695b2b379c591a0a402cf638e062d8ae84f516684bb72e8a7a6e4e71e3c66
5
5
  SHA512:
6
- metadata.gz: 253d562cff1325f5218f89b6d800d6e656eeb3c8c5067a38581271720161c55a181c2fbba3e2ff815219805438af9dea258e59e6b00f12ba8485db172d4abab3
7
- data.tar.gz: defe6add59ce6268f5d16f3ccc7f20da40c7436f686dfafd5d66cc2f4ed8aedc1a591e2eb1da69cdcfbaf4693fe19d0ba46e8a5d1e297170fbed8a1fec5d717a
6
+ metadata.gz: e3ac01c79b99a587b32f633dc5ec7d7df26688bdbf5ce24886a8c62f2dd8d13b2db518eeaed4912340b432fcbeee02ffac547ade62d3b7e44e846d3e3c79e089
7
+ data.tar.gz: 8e39fda010cb4a33cfbc00e390ddf750ffa57d4e39396eed007b489b04a67c1d8be8d3f0ef73930e9f9e9ba4bf714ed27fcea1c9cf3caecb6cc749afb856352c
data/Rakefile CHANGED
@@ -20,7 +20,7 @@ GemHadar do
20
20
  readme 'README.md'
21
21
  licenses << 'GPL-2.0'
22
22
 
23
- dependency 'unix_socks', '~> 0.2'
23
+ dependency 'unix_socks', '~> 0.3'
24
24
  dependency 'tins', '~> 1.51'
25
25
  dependency 'term-ansicolor', '~> 1.11'
26
26
  dependency 'pstree', '~> 0.3'
data/bin/code_comment CHANGED
@@ -184,7 +184,7 @@ end
184
184
  filename_linenumber = ARGV.shift or fail "require file_name as second argument"
185
185
  $config = Utils::ConfigFile.new
186
186
  $config.configure_from_paths
187
- $config_dir = Utils::ConfigDir.new('code_comment', env_var: 'XDG_CONFIG_HOME')
187
+ $config_dir = Utils::ConfigDir.new('code_comment', env_var: 'XDG_CONFIG_HOME')
188
188
  base_url = ENV['OLLAMA_URL'] || 'http://%s' % ENV.fetch('OLLAMA_HOST')
189
189
  model = ENV.fetch('OLLAMA_MODEL', 'llama3.1')
190
190
  construct, construct_type = fetch_construct(filename_linenumber)
data/bin/probe CHANGED
@@ -14,6 +14,7 @@
14
14
 
15
15
  require 'utils'
16
16
  include Utils
17
+ include Utils::Probe
17
18
  include Tins::GO
18
19
  require 'shellwords'
19
20
 
@@ -78,7 +79,10 @@ end
78
79
  # probe server instance to handle incoming requests and process jobs.
79
80
  def start_server
80
81
  Thread.abort_on_exception = $DEBUG
81
- Utils::ProbeServer.new.start
82
+ ProbeServer.new(
83
+ server_type: $config.probe.server_type,
84
+ port: $config.probe.tcp_server_port
85
+ ).start
82
86
  end
83
87
 
84
88
  # The connect_server method establishes a connection to a probe server and
@@ -89,7 +93,10 @@ end
89
93
  # It also enqueues jobs for execution on the probe server when specified.
90
94
  #
91
95
  def connect_server
92
- probe_client = ProbeClient.new
96
+ probe_client = ProbeClient.new(
97
+ server_type: $config.probe.server_type,
98
+ port: $config.probe.tcp_server_port
99
+ )
93
100
  if setting = $opts[?C]
94
101
  case setting
95
102
  when /\A([^=]+)=([^=]+)\z/
@@ -31,20 +31,6 @@ module Utils
31
31
  @directory_path = derive_directory_path(name, root_path)
32
32
  end
33
33
 
34
- # Memoizes the foobar method's return value and returns the result of the computation.
35
- # Initializes a new ConfigDir instance with the specified name and optional
36
- # root path or environment variable.
37
- #
38
- # @param name [ String ] the name of the directory to be used
39
- # @param root_path [ String, nil ] the root path to use; if nil, the
40
- # default root path is used
41
- # @param env_var [ String, nil ] the name of the environment variable to
42
- # check for the root path
43
- def initialize(name, root_path: nil, env_var: nil)
44
- root_path ||= env_var_path(env_var)
45
- @directory_path = derive_directory_path(name, root_path)
46
- end
47
-
48
34
  # Returns the string representation of the configuration directory path.
49
35
  #
50
36
  # @return [ String ] the path of the configuration directory as a string
@@ -224,6 +224,23 @@ class Utils::ConfigFile
224
224
  # @param dirs [ Array<String> ] the array of directory names to include
225
225
  config :include_dirs, %w[lib test tests ext spec]
226
226
 
227
+ # The server_type method configures the type of server to be used.
228
+ #
229
+ # This method sets up the server type configuration option, which
230
+ # determines the underlying server implementation to be utilized, this is
231
+ # either :unix for UNIX domain sockets or :tcp for TCP Sockets.
232
+ #
233
+ # @return [ Symbol ] returns the server type configured
234
+ config :server_type, :unix
235
+
236
+ # The tcp_server_port method configures the TCP server port setting.
237
+ #
238
+ # This method sets up a configuration option that specifies the port number
239
+ # to be used for TCP server operations.
240
+ #
241
+ # @param value [ Integer ] the TCP server port number to use
242
+ config :tcp_server_port, 59999
243
+
227
244
  # The include_dirs_argument method constructs a colon-separated string from
228
245
  # include directories.
229
246
  #
data/lib/utils/irb.rb CHANGED
@@ -2,6 +2,7 @@ require 'irb/completion'
2
2
  require 'enumerator'
3
3
  require 'tempfile'
4
4
  require 'pp'
5
+ require 'shellwords'
5
6
  require 'utils'
6
7
  require_maybe 'ap'
7
8
 
@@ -83,6 +84,48 @@ module Utils
83
84
  ri(*patterns, doc: 'yri')
84
85
  end
85
86
 
87
+ # The ai method interacts with an Ollama chat service to process queries
88
+ # and optionally return responses.
89
+ #
90
+ # This method constructs command-line arguments for the ollama_chat_send
91
+ # utility based on the provided options, executes the command with the
92
+ # query as input, and returns the response if requested.
93
+ #
94
+ # @param query [ String ] the input query to send to the Ollama chat
95
+ # service
96
+ # @param command [ TrueClass, FalseClass ] whether to treat the query as
97
+ # a command
98
+ # @param respond [ TrueClass, FalseClass ] whether to capture and return
99
+ # the response from the service
100
+ # @param parse [ TrueClass, FalseClass ] whether to parse the response
101
+ # @param dir [ String ] the directory to use for the operation
102
+ #
103
+ # @return [ String, nil ] the response from the Ollama chat service if
104
+ # respond is true, otherwise nil
105
+ def ai(query, command: false, respond: false, parse: false, dir: ?.)
106
+ dir = File.expand_path(dir)
107
+ args = {
108
+ ?r => respond,
109
+ ?t => command,
110
+ ?p => parse,
111
+ ?d => dir,
112
+ }
113
+ args = args.map { |k, v|
114
+ v == false and next
115
+ v == true ? "-#{k}" : [ "-#{k}", v.to_s ]
116
+ }.flatten.compact
117
+ args.unshift 'ollama_chat_send'
118
+ response = nil
119
+ IO.popen(Shellwords.join(args), 'r+') do |io|
120
+ io.write query
121
+ io.close_write
122
+ if respond
123
+ response = io.read
124
+ end
125
+ end
126
+ response
127
+ end
128
+
86
129
  # The irb_open method opens a URL or executes a block to capture output
87
130
  # and open it.
88
131
  #
@@ -0,0 +1,98 @@
1
+ module Utils::Probe
2
+ # A client for interacting with the probe server through Unix domain sockets.
3
+ #
4
+ # This class provides an interface for enqueueing process jobs and managing
5
+ # environment variables on a remote probe server. It uses Unix domain sockets
6
+ # to communicate with the server, enabling distributed task execution and
7
+ # configuration management.
8
+ class ProbeClient
9
+ include ServerHandling
10
+
11
+ # A proxy class for managing environment variables through a probe server communication channel.
12
+ #
13
+ # This class provides a wrapper around the ENV object that allows setting and retrieving
14
+ # environment variables while logging these operations through the probe server.
15
+ # It intercepts assignments and lookups to provide visibility into environment modifications
16
+ # during probe server operations.
17
+ class EnvProxy
18
+ # The initialize method sets up a new instance with the provided server
19
+ # object.
20
+ #
21
+ # @param server [ UnixSocks::Server ] the server object to be assigned
22
+ # to the instance variable
23
+ def initialize(server)
24
+ @server = server
25
+ end
26
+
27
+ # The []= method sets an environment variable value through the probe server.
28
+ #
29
+ # This method transmits a request to the probe server to set the specified
30
+ # environment variable key to the given value, then returns the updated
31
+ # environment value from the server's response.
32
+ #
33
+ # @param key [ String ] the environment variable key to set
34
+ # @param value [ String ] the value to assign to the environment variable
35
+ #
36
+ # @return [ String ] the updated environment variable value returned by the server
37
+ def []=(key, value)
38
+ response = @server.transmit_with_response(type: 'set_env', key:, value:)
39
+ response.env
40
+ end
41
+
42
+ # The [] method retrieves the value of an environment variable from the probe server.
43
+ #
44
+ # This method sends a request to the probe server to fetch the current value of the specified
45
+ # environment variable key and returns the corresponding value.
46
+ #
47
+ # @param key [ String ] the environment variable key to retrieve
48
+ #
49
+ # @return [ String ] the value of the specified environment variable
50
+ def [](key)
51
+ response = @server.transmit_with_response(type: 'get_env', key:)
52
+ response.env
53
+ end
54
+
55
+ attr_reader :env
56
+ end
57
+
58
+ # The initialize method sets up a new probe server instance.
59
+ #
60
+ # This method creates and configures a Unix domain socket server for
61
+ # handling probe jobs and communication. It initializes the server with a
62
+ # specific socket name and runtime directory, preparing it to listen for
63
+ # incoming connections and process jobs.
64
+ #
65
+ # @return [ Utils::ProbeServer ] a new probe server instance configured with
66
+ # the specified socket name and runtime directory
67
+ def initialize(server_type: :unix, port: 6666)
68
+ @server = create_server(server_type, port)
69
+ end
70
+
71
+ # The env method provides access to environment variable management through
72
+ # a proxy object.
73
+ #
74
+ # This method returns an EnvProxy instance that allows for setting and
75
+ # retrieving environment variables via the probe server communication
76
+ # channel.
77
+ #
78
+ # @return [ Utils::ProbeServer::EnvProxy ] a proxy object for environment
79
+ # variable operations
80
+ def env
81
+ EnvProxy.new(@server)
82
+ end
83
+
84
+ # The enqueue method submits a new process job to the probe server for
85
+ # execution.
86
+ #
87
+ # This method transmits a process job request to the underlying Unix domain
88
+ # socket server, which then adds the job to the processing queue. The job
89
+ # includes the specified command arguments that will be executed by the
90
+ # probe server.
91
+ #
92
+ # @param args [ Array ] the command arguments to be executed by the process
93
+ # job
94
+ def enqueue(args)
95
+ @server.transmit({ type: 'process_job', args: })
96
+ end
97
+ end
98
+ end
@@ -1,231 +1,4 @@
1
- require 'unix_socks'
2
- require 'term/ansicolor'
3
-
4
- module Utils
5
- # A process job representation for execution within the probe server system.
6
- #
7
- # This class encapsulates the information and behavior associated with a
8
- # single executable task that can be enqueued and processed by a ProbeServer.
9
- # It holds command arguments, manages execution status, and provides
10
- # mechanisms for serialization and display of job information.
11
- class ProcessJob
12
- include Term::ANSIColor
13
-
14
- # Initializes a new ProcessJob instance with the specified arguments and
15
- # optional probe server.
16
- #
17
- # This method creates a process job object that can be enqueued for
18
- # execution by a probe server. It assigns a unique job ID from the probe
19
- # server if provided and stores the command arguments as an array.
20
- #
21
- # @param args [ Array ] the command arguments to be executed by the job
22
- # @param probe_server [ Utils::ProbeServer, nil ] the probe server instance
23
- # to use for generating job IDs
24
- #
25
- # @return [ Utils::ProcessJob ] a new ProcessJob instance configured with
26
- # the provided arguments and server reference
27
- def initialize(args:, probe_server: nil)
28
- @id = probe_server&.next_job_id
29
- @args = Array(args)
30
- end
31
-
32
- # Returns the unique identifier of the process job.
33
- #
34
- # @return [ Integer ] the job ID
35
- attr_reader :id
36
-
37
- # The args reader method provides access to the arguments stored in the
38
- # instance.
39
- #
40
- # @return [ Array ] the array of arguments
41
- attr_reader :args
42
-
43
- # The ok method sets the success status of the process job.
44
- #
45
- # @param value [ TrueClass, FalseClass, nil ] the success status to set
46
- attr_writer :ok
47
-
48
- # Returns the type identifier for the process job.
49
- #
50
- # This method provides a constant string value that identifies the object
51
- # as a process job within the probe server system, facilitating type-based
52
- # dispatch and handling.
53
- #
54
- # @return [ String ] the string 'process_job' indicating the object's type
55
- def type
56
- 'process_job'
57
- end
58
-
59
- # The ok method returns a character representation of the job's success
60
- # status.
61
- #
62
- # This method provides a visual indicator of whether a process job has
63
- # succeeded, failed, or is still in progress. It returns 'y' for successful
64
- # jobs, 'n' for failed jobs, and '…' for jobs that are currently running or
65
- # pending.
66
- #
67
- # @return [ String ] 'y' if the job succeeded, 'n' if it failed, or '…' if
68
- # the status is unknown
69
- def ok
70
- case @ok
71
- when false then 'n'
72
- when true then 'y'
73
- else '…'
74
- end
75
- end
76
-
77
- # The ok_colorize method applies color formatting to a string based on the
78
- # success status.
79
- #
80
- # This method returns the input string wrapped with color codes to indicate
81
- # whether the associated process job succeeded, failed, or is in progress.
82
- # Successful jobs are highlighted in green, failed jobs in red, and pending
83
- # jobs are returned without any color formatting.
84
- #
85
- # @param string [ String ] the string to be colorized
86
- #
87
- # @return [ String ] the colorized string or the original string if status is unknown
88
- def ok_colorize(string)
89
- case @ok
90
- when false then white { on_red { string } }
91
- when true then black { on_green { string } }
92
- else string
93
- end
94
- end
95
-
96
- # The inspect method generates a colorized string representation of the
97
- # process job.
98
- #
99
- # This method creates a formatted string that includes the job's unique
100
- # identifier and its command arguments, with the status indicator
101
- # color-coded based on whether the job succeeded, failed, or is pending.
102
- #
103
- # @return [ String ] a formatted string representation of the process job
104
- # including its ID, arguments, and color-coded status indicator
105
- def inspect
106
- ok_colorize("#{id} #{args.map { |a| a.include?(' ') ? a.inspect : a } * ' '}")
107
- end
108
-
109
- alias to_s inspect
110
-
111
- # The as_json method converts the process job object into a
112
- # JSON-serializable hash.
113
- #
114
- # This method creates and returns a hash representation of the process job,
115
- # containing its type, unique identifier, and command arguments.
116
- #
117
- # @return [ Hash ] a hash containing the type, id, and args of the process job
118
- def as_json(*)
119
- { type:, id:, args:, }
120
- end
121
-
122
- # The to_json method converts the object to a JSON string representation.
123
- #
124
- # This method delegates to the as_json method to generate a hash representation
125
- # of the object, then converts that hash to a JSON string using the
126
- # standard JSON library's to_json method.
127
- #
128
- # @return [ String ] a JSON string representation of the object
129
- def to_json(*)
130
- as_json.to_json(*)
131
- end
132
- end
133
-
134
- # A client for interacting with the probe server through Unix domain sockets.
135
- #
136
- # This class provides an interface for enqueueing process jobs and managing
137
- # environment variables on a remote probe server. It uses Unix domain sockets
138
- # to communicate with the server, enabling distributed task execution and
139
- # configuration management.
140
- class ProbeClient
141
- # A proxy class for managing environment variables through a probe server communication channel.
142
- #
143
- # This class provides a wrapper around the ENV object that allows setting and retrieving
144
- # environment variables while logging these operations through the probe server.
145
- # It intercepts assignments and lookups to provide visibility into environment modifications
146
- # during probe server operations.
147
- class EnvProxy
148
- # The initialize method sets up a new instance with the provided server
149
- # object.
150
- #
151
- # @param server [ UnixSocks::Server ] the server object to be assigned
152
- # to the instance variable
153
- def initialize(server)
154
- @server = server
155
- end
156
-
157
- # The []= method sets an environment variable value through the probe server.
158
- #
159
- # This method transmits a request to the probe server to set the specified
160
- # environment variable key to the given value, then returns the updated
161
- # environment value from the server's response.
162
- #
163
- # @param key [ String ] the environment variable key to set
164
- # @param value [ String ] the value to assign to the environment variable
165
- #
166
- # @return [ String ] the updated environment variable value returned by the server
167
- def []=(key, value)
168
- response = @server.transmit_with_response(type: 'set_env', key:, value:)
169
- response.env
170
- end
171
-
172
- # The [] method retrieves the value of an environment variable from the probe server.
173
- #
174
- # This method sends a request to the probe server to fetch the current value of the specified
175
- # environment variable key and returns the corresponding value.
176
- #
177
- # @param key [ String ] the environment variable key to retrieve
178
- #
179
- # @return [ String ] the value of the specified environment variable
180
- def [](key)
181
- response = @server.transmit_with_response(type: 'get_env', key:)
182
- response.env
183
- end
184
-
185
- attr_reader :env
186
- end
187
-
188
- # The initialize method sets up a new probe server instance.
189
- #
190
- # This method creates and configures a Unix domain socket server for
191
- # handling probe jobs and communication. It initializes the server with a
192
- # specific socket name and runtime directory, preparing it to listen for
193
- # incoming connections and process jobs.
194
- #
195
- # @return [ Utils::ProbeServer ] a new probe server instance configured with
196
- # the specified socket name and runtime directory
197
- def initialize
198
- @server = UnixSocks::Server.new(socket_name: 'probe.sock', runtime_dir: Dir.pwd)
199
- end
200
-
201
- # The env method provides access to environment variable management through
202
- # a proxy object.
203
- #
204
- # This method returns an EnvProxy instance that allows for setting and
205
- # retrieving environment variables via the probe server communication
206
- # channel.
207
- #
208
- # @return [ Utils::ProbeServer::EnvProxy ] a proxy object for environment
209
- # variable operations
210
- def env
211
- EnvProxy.new(@server)
212
- end
213
-
214
- # The enqueue method submits a new process job to the probe server for
215
- # execution.
216
- #
217
- # This method transmits a process job request to the underlying Unix domain
218
- # socket server, which then adds the job to the processing queue. The job
219
- # includes the specified command arguments that will be executed by the
220
- # probe server.
221
- #
222
- # @param args [ Array ] the command arguments to be executed by the process
223
- # job
224
- def enqueue(args)
225
- @server.transmit({ type: 'process_job', args: })
226
- end
227
- end
228
-
1
+ module Utils::Probe
229
2
  # A probe server for managing and executing process jobs through Unix domain
230
3
  # sockets.
231
4
  #
@@ -234,6 +7,7 @@ module Utils
234
7
  # maintains a queue of jobs, tracks their execution status, and provides an
235
8
  # interactive interface for managing the server.
236
9
  class ProbeServer
10
+ include Utils::Probe::ServerHandling
237
11
  include Term::ANSIColor
238
12
 
239
13
  # The initialize method sets up a new probe server instance.
@@ -245,8 +19,8 @@ module Utils
245
19
  #
246
20
  # @return [ Utils::ProbeServer ] a new probe server instance configured
247
21
  # with the specified socket name and runtime directory
248
- def initialize
249
- @server = UnixSocks::Server.new(socket_name: 'probe.sock', runtime_dir: Dir.pwd)
22
+ def initialize(server_type: :unix, port: 6666)
23
+ @server = create_server(server_type, port)
250
24
  @history = [].freeze
251
25
  @jobs_queue = Queue.new
252
26
  @current_job_id = 0
@@ -258,7 +32,7 @@ module Utils
258
32
  # from the queue and entering a receive loop to handle incoming requests.
259
33
  # It also manages interrupt signals to enter interactive mode when needed.
260
34
  def start
261
- output_message "Starting probe server listening to #{@server.server_socket_path}.", type: :info
35
+ output_message "Starting probe server listening to #{@server.to_url}", type: :info
262
36
  Thread.new do
263
37
  loop do
264
38
  job = @jobs_queue.pop
@@ -278,7 +52,7 @@ module Utils
278
52
  $VERBOSE = old
279
53
  end
280
54
  @server.remove_socket_path
281
- output_message "Quitting interactive mode, but still listening to #{@server.server_socket_path}.", type: :info
55
+ output_message "Quitting interactive mode, but still listening to #{@server.to_url}", type: :info
282
56
  retry
283
57
  end
284
58
  end
@@ -0,0 +1,130 @@
1
+ module Utils::Probe
2
+ # A process job representation for execution within the probe server system.
3
+ #
4
+ # This class encapsulates the information and behavior associated with a
5
+ # single executable task that can be enqueued and processed by a ProbeServer.
6
+ # It holds command arguments, manages execution status, and provides
7
+ # mechanisms for serialization and display of job information.
8
+ class ProcessJob
9
+ include Term::ANSIColor
10
+
11
+ # Initializes a new ProcessJob instance with the specified arguments and
12
+ # optional probe server.
13
+ #
14
+ # This method creates a process job object that can be enqueued for
15
+ # execution by a probe server. It assigns a unique job ID from the probe
16
+ # server if provided and stores the command arguments as an array.
17
+ #
18
+ # @param args [ Array ] the command arguments to be executed by the job
19
+ # @param probe_server [ Utils::ProbeServer, nil ] the probe server instance
20
+ # to use for generating job IDs
21
+ #
22
+ # @return [ Utils::ProcessJob ] a new ProcessJob instance configured with
23
+ # the provided arguments and server reference
24
+ def initialize(args:, probe_server: nil)
25
+ @id = probe_server&.next_job_id
26
+ @args = Array(args)
27
+ end
28
+
29
+ # Returns the unique identifier of the process job.
30
+ #
31
+ # @return [ Integer ] the job ID
32
+ attr_reader :id
33
+
34
+ # The args reader method provides access to the arguments stored in the
35
+ # instance.
36
+ #
37
+ # @return [ Array ] the array of arguments
38
+ attr_reader :args
39
+
40
+ # The ok method sets the success status of the process job.
41
+ #
42
+ # @param value [ TrueClass, FalseClass, nil ] the success status to set
43
+ attr_writer :ok
44
+
45
+ # Returns the type identifier for the process job.
46
+ #
47
+ # This method provides a constant string value that identifies the object
48
+ # as a process job within the probe server system, facilitating type-based
49
+ # dispatch and handling.
50
+ #
51
+ # @return [ String ] the string 'process_job' indicating the object's type
52
+ def type
53
+ 'process_job'
54
+ end
55
+
56
+ # The ok method returns a character representation of the job's success
57
+ # status.
58
+ #
59
+ # This method provides a visual indicator of whether a process job has
60
+ # succeeded, failed, or is still in progress. It returns 'y' for successful
61
+ # jobs, 'n' for failed jobs, and '…' for jobs that are currently running or
62
+ # pending.
63
+ #
64
+ # @return [ String ] 'y' if the job succeeded, 'n' if it failed, or '…' if
65
+ # the status is unknown
66
+ def ok
67
+ case @ok
68
+ when false then 'n'
69
+ when true then 'y'
70
+ else '…'
71
+ end
72
+ end
73
+
74
+ # The ok_colorize method applies color formatting to a string based on the
75
+ # success status.
76
+ #
77
+ # This method returns the input string wrapped with color codes to indicate
78
+ # whether the associated process job succeeded, failed, or is in progress.
79
+ # Successful jobs are highlighted in green, failed jobs in red, and pending
80
+ # jobs are returned without any color formatting.
81
+ #
82
+ # @param string [ String ] the string to be colorized
83
+ #
84
+ # @return [ String ] the colorized string or the original string if status is unknown
85
+ def ok_colorize(string)
86
+ case @ok
87
+ when false then white { on_red { string } }
88
+ when true then black { on_green { string } }
89
+ else string
90
+ end
91
+ end
92
+
93
+ # The inspect method generates a colorized string representation of the
94
+ # process job.
95
+ #
96
+ # This method creates a formatted string that includes the job's unique
97
+ # identifier and its command arguments, with the status indicator
98
+ # color-coded based on whether the job succeeded, failed, or is pending.
99
+ #
100
+ # @return [ String ] a formatted string representation of the process job
101
+ # including its ID, arguments, and color-coded status indicator
102
+ def inspect
103
+ ok_colorize("#{id} #{args.map { |a| a.include?(' ') ? a.inspect : a } * ' '}")
104
+ end
105
+
106
+ alias to_s inspect
107
+
108
+ # The as_json method converts the process job object into a
109
+ # JSON-serializable hash.
110
+ #
111
+ # This method creates and returns a hash representation of the process job,
112
+ # containing its type, unique identifier, and command arguments.
113
+ #
114
+ # @return [ Hash ] a hash containing the type, id, and args of the process job
115
+ def as_json(*)
116
+ { type:, id:, args:, }
117
+ end
118
+
119
+ # The to_json method converts the object to a JSON string representation.
120
+ #
121
+ # This method delegates to the as_json method to generate a hash representation
122
+ # of the object, then converts that hash to a JSON string using the
123
+ # standard JSON library's to_json method.
124
+ #
125
+ # @return [ String ] a JSON string representation of the object
126
+ def to_json(*)
127
+ as_json.to_json(*)
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,32 @@
1
+ module Utils::Probe
2
+ # A module that provides server handling functionality for creating and
3
+ # managing socket servers.
4
+ #
5
+ # This module encapsulates the logic for initializing different types of
6
+ # socket servers based on the specified server type, supporting both TCP and
7
+ # domain socket configurations. It provides a centralized approach to server
8
+ # creation and management within the Utils library.
9
+ module ServerHandling
10
+ # The create_server method initializes and returns a socket server instance
11
+ # based on the specified server type.
12
+ #
13
+ # This method creates either a TCP socket server or a domain socket server
14
+ # depending on the server type parameter. It configures the server with the
15
+ # appropriate parameters including port number for TCP servers or socket
16
+ # name and runtime directory for domain sockets.
17
+ #
18
+ # @param server_type [ Symbol ] the type of socket server to create, either :tcp or another value for domain socket
19
+ # @param port [ Integer ] the port number to use for TCP socket server creation
20
+ #
21
+ # @return [ UnixSocks::TCPSocketServer, UnixSocks::DomainSocketServer ] a
22
+ # new socket server instance of the specified type
23
+ def create_server(server_type, port)
24
+ case server_type
25
+ when :tcp
26
+ UnixSocks::TCPSocketServer.new(port:)
27
+ else
28
+ UnixSocks::DomainSocketServer.new(socket_name: 'probe.sock', runtime_dir: Dir.pwd)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,23 @@
1
+ # A module that provides probe server functionality for managing and executing
2
+ # process jobs through Unix domain sockets.
3
+ #
4
+ # This module encapsulates the core components for creating and interacting
5
+ # with probe servers that can enqueue and run process jobs in a distributed
6
+ # manner.
7
+ #
8
+ # The module includes classes for handling server communication, managing
9
+ # process jobs, and providing client interfaces for interacting with probe
10
+ # servers.
11
+ #
12
+ # It supports both TCP and Unix domain socket configurations for server
13
+ # communication and provides mechanisms for environment variable management and
14
+ # job execution tracking.
15
+ module Utils::Probe
16
+ end
17
+
18
+ require 'unix_socks'
19
+ require 'term/ansicolor'
20
+ require 'utils/probe/server_handling'
21
+ require 'utils/probe/process_job'
22
+ require 'utils/probe/probe_server'
23
+ require 'utils/probe/probe_client'
data/lib/utils/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Utils
2
2
  # Utils version
3
- VERSION = '0.80.0'
3
+ VERSION = '0.82.0'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
data/lib/utils.rb CHANGED
@@ -14,7 +14,7 @@ module Utils
14
14
  require 'utils/editor'
15
15
  require 'utils/finder'
16
16
  require 'utils/grepper'
17
- require 'utils/probe_server'
17
+ require 'utils/probe'
18
18
  require 'utils/ssh_tunnel_specification'
19
19
  require 'utils/line_blamer'
20
20
  require 'utils/config_dir'
data/utils.gemspec CHANGED
@@ -1,9 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: utils 0.80.0 ruby lib
2
+ # stub: utils 0.82.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "utils".freeze
6
- s.version = "0.80.0".freeze
6
+ s.version = "0.82.0".freeze
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
@@ -12,8 +12,8 @@ Gem::Specification.new do |s|
12
12
  s.description = "This ruby gem provides some useful command line utilities".freeze
13
13
  s.email = "flori@ping.de".freeze
14
14
  s.executables = ["ascii7".freeze, "blameline".freeze, "changes".freeze, "classify".freeze, "code_comment".freeze, "code_indexer".freeze, "commit_message".freeze, "discover".freeze, "edit".freeze, "edit_wait".freeze, "enum".freeze, "git-empty".freeze, "git-versions".freeze, "json_check".freeze, "long_lines".freeze, "myex".freeze, "on_change".freeze, "path".freeze, "print_method".freeze, "probe".freeze, "rainbow".freeze, "rd2md".freeze, "search".freeze, "sedit".freeze, "serve".freeze, "ssh-tunnel".freeze, "strip_spaces".freeze, "sync_dir".freeze, "untest".freeze, "utils-utilsrc".freeze, "vcf2alias".freeze, "yaml_check".freeze]
15
- s.extra_rdoc_files = ["README.md".freeze, "lib/utils.rb".freeze, "lib/utils/config_dir.rb".freeze, "lib/utils/config_file.rb".freeze, "lib/utils/editor.rb".freeze, "lib/utils/finder.rb".freeze, "lib/utils/grepper.rb".freeze, "lib/utils/irb.rb".freeze, "lib/utils/line_blamer.rb".freeze, "lib/utils/line_formatter.rb".freeze, "lib/utils/md5.rb".freeze, "lib/utils/patterns.rb".freeze, "lib/utils/probe_server.rb".freeze, "lib/utils/ssh_tunnel_specification.rb".freeze, "lib/utils/version.rb".freeze, "lib/utils/xt/source_location_extension.rb".freeze]
16
- s.files = ["Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "bin/ascii7".freeze, "bin/blameline".freeze, "bin/changes".freeze, "bin/classify".freeze, "bin/code_comment".freeze, "bin/code_indexer".freeze, "bin/commit_message".freeze, "bin/discover".freeze, "bin/edit".freeze, "bin/edit_wait".freeze, "bin/enum".freeze, "bin/git-empty".freeze, "bin/git-versions".freeze, "bin/json_check".freeze, "bin/long_lines".freeze, "bin/myex".freeze, "bin/on_change".freeze, "bin/path".freeze, "bin/print_method".freeze, "bin/probe".freeze, "bin/rainbow".freeze, "bin/rd2md".freeze, "bin/search".freeze, "bin/sedit".freeze, "bin/serve".freeze, "bin/ssh-tunnel".freeze, "bin/strip_spaces".freeze, "bin/sync_dir".freeze, "bin/untest".freeze, "bin/utils-utilsrc".freeze, "bin/vcf2alias".freeze, "bin/yaml_check".freeze, "lib/utils.rb".freeze, "lib/utils/config_dir.rb".freeze, "lib/utils/config_file.rb".freeze, "lib/utils/editor.rb".freeze, "lib/utils/finder.rb".freeze, "lib/utils/grepper.rb".freeze, "lib/utils/irb.rb".freeze, "lib/utils/line_blamer.rb".freeze, "lib/utils/line_formatter.rb".freeze, "lib/utils/md5.rb".freeze, "lib/utils/patterns.rb".freeze, "lib/utils/probe_server.rb".freeze, "lib/utils/ssh_tunnel_specification.rb".freeze, "lib/utils/version.rb".freeze, "lib/utils/xt/source_location_extension.rb".freeze, "tests/test_helper.rb".freeze, "tests/utils_test.rb".freeze, "utils.gemspec".freeze]
15
+ s.extra_rdoc_files = ["README.md".freeze, "lib/utils.rb".freeze, "lib/utils/config_dir.rb".freeze, "lib/utils/config_file.rb".freeze, "lib/utils/editor.rb".freeze, "lib/utils/finder.rb".freeze, "lib/utils/grepper.rb".freeze, "lib/utils/irb.rb".freeze, "lib/utils/line_blamer.rb".freeze, "lib/utils/line_formatter.rb".freeze, "lib/utils/md5.rb".freeze, "lib/utils/patterns.rb".freeze, "lib/utils/probe.rb".freeze, "lib/utils/probe/probe_client.rb".freeze, "lib/utils/probe/probe_server.rb".freeze, "lib/utils/probe/process_job.rb".freeze, "lib/utils/probe/server_handling.rb".freeze, "lib/utils/ssh_tunnel_specification.rb".freeze, "lib/utils/version.rb".freeze, "lib/utils/xt/source_location_extension.rb".freeze]
16
+ s.files = ["Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "bin/ascii7".freeze, "bin/blameline".freeze, "bin/changes".freeze, "bin/classify".freeze, "bin/code_comment".freeze, "bin/code_indexer".freeze, "bin/commit_message".freeze, "bin/discover".freeze, "bin/edit".freeze, "bin/edit_wait".freeze, "bin/enum".freeze, "bin/git-empty".freeze, "bin/git-versions".freeze, "bin/json_check".freeze, "bin/long_lines".freeze, "bin/myex".freeze, "bin/on_change".freeze, "bin/path".freeze, "bin/print_method".freeze, "bin/probe".freeze, "bin/rainbow".freeze, "bin/rd2md".freeze, "bin/search".freeze, "bin/sedit".freeze, "bin/serve".freeze, "bin/ssh-tunnel".freeze, "bin/strip_spaces".freeze, "bin/sync_dir".freeze, "bin/untest".freeze, "bin/utils-utilsrc".freeze, "bin/vcf2alias".freeze, "bin/yaml_check".freeze, "lib/utils.rb".freeze, "lib/utils/config_dir.rb".freeze, "lib/utils/config_file.rb".freeze, "lib/utils/editor.rb".freeze, "lib/utils/finder.rb".freeze, "lib/utils/grepper.rb".freeze, "lib/utils/irb.rb".freeze, "lib/utils/line_blamer.rb".freeze, "lib/utils/line_formatter.rb".freeze, "lib/utils/md5.rb".freeze, "lib/utils/patterns.rb".freeze, "lib/utils/probe.rb".freeze, "lib/utils/probe/probe_client.rb".freeze, "lib/utils/probe/probe_server.rb".freeze, "lib/utils/probe/process_job.rb".freeze, "lib/utils/probe/server_handling.rb".freeze, "lib/utils/ssh_tunnel_specification.rb".freeze, "lib/utils/version.rb".freeze, "lib/utils/xt/source_location_extension.rb".freeze, "tests/test_helper.rb".freeze, "tests/utils_test.rb".freeze, "utils.gemspec".freeze]
17
17
  s.homepage = "http://github.com/flori/utils".freeze
18
18
  s.licenses = ["GPL-2.0".freeze]
19
19
  s.rdoc_options = ["--title".freeze, "Utils - Some useful command line utilities".freeze, "--main".freeze, "README.md".freeze]
@@ -23,9 +23,9 @@ Gem::Specification.new do |s|
23
23
 
24
24
  s.specification_version = 4
25
25
 
26
- s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 2.10".freeze])
26
+ s.add_development_dependency(%q<gem_hadar>.freeze, [">= 2.16.2".freeze])
27
27
  s.add_development_dependency(%q<test-unit>.freeze, [">= 0".freeze])
28
- s.add_runtime_dependency(%q<unix_socks>.freeze, ["~> 0.2".freeze])
28
+ s.add_runtime_dependency(%q<unix_socks>.freeze, ["~> 0.3".freeze])
29
29
  s.add_runtime_dependency(%q<tins>.freeze, ["~> 1.51".freeze])
30
30
  s.add_runtime_dependency(%q<term-ansicolor>.freeze, ["~> 1.11".freeze])
31
31
  s.add_runtime_dependency(%q<pstree>.freeze, ["~> 0.3".freeze])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.80.0
4
+ version: 0.82.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
@@ -13,16 +13,16 @@ dependencies:
13
13
  name: gem_hadar
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
- - - "~>"
16
+ - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: '2.10'
18
+ version: 2.16.2
19
19
  type: :development
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
- - - "~>"
23
+ - - ">="
24
24
  - !ruby/object:Gem::Version
25
- version: '2.10'
25
+ version: 2.16.2
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: test-unit
28
28
  requirement: !ruby/object:Gem::Requirement
@@ -43,14 +43,14 @@ dependencies:
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '0.2'
46
+ version: '0.3'
47
47
  type: :runtime
48
48
  prerelease: false
49
49
  version_requirements: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '0.2'
53
+ version: '0.3'
54
54
  - !ruby/object:Gem::Dependency
55
55
  name: tins
56
56
  requirement: !ruby/object:Gem::Requirement
@@ -310,7 +310,11 @@ extra_rdoc_files:
310
310
  - lib/utils/line_formatter.rb
311
311
  - lib/utils/md5.rb
312
312
  - lib/utils/patterns.rb
313
- - lib/utils/probe_server.rb
313
+ - lib/utils/probe.rb
314
+ - lib/utils/probe/probe_client.rb
315
+ - lib/utils/probe/probe_server.rb
316
+ - lib/utils/probe/process_job.rb
317
+ - lib/utils/probe/server_handling.rb
314
318
  - lib/utils/ssh_tunnel_specification.rb
315
319
  - lib/utils/version.rb
316
320
  - lib/utils/xt/source_location_extension.rb
@@ -362,7 +366,11 @@ files:
362
366
  - lib/utils/line_formatter.rb
363
367
  - lib/utils/md5.rb
364
368
  - lib/utils/patterns.rb
365
- - lib/utils/probe_server.rb
369
+ - lib/utils/probe.rb
370
+ - lib/utils/probe/probe_client.rb
371
+ - lib/utils/probe/probe_server.rb
372
+ - lib/utils/probe/process_job.rb
373
+ - lib/utils/probe/server_handling.rb
366
374
  - lib/utils/ssh_tunnel_specification.rb
367
375
  - lib/utils/version.rb
368
376
  - lib/utils/xt/source_location_extension.rb