utils 0.73.1 → 0.74.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: eeb8c50e8895ed05192b62c4c7c86d0f5eccd34234e6878233c5324542c2c5ef
4
- data.tar.gz: f0c4adb49862333e4c85fba3ccde54c1a899dffb23a0cd846123d4bcc6ee7fa8
3
+ metadata.gz: 86f1322a16463dd1af9021e0d2a9dc63dfc3704bdf3a8c71874c8f526b8aac0c
4
+ data.tar.gz: 8b645c35b3b852f14ad94aee06820b2c15da09306315e4061251e00f318d476c
5
5
  SHA512:
6
- metadata.gz: 18e205eb300082bdd1341083a63ac508c80e3af31faabcbe4675ec4c2c7c3c7b5975e1479ec426aba98ebadad3dc2d8e66b0b351aeae092eb525a1caf23ff1a7
7
- data.tar.gz: 8c3f8ec933935f36b4d79e5224dd49e71f5839bc152969f528b459f19240e743089ff7234e17eb644d6e19dda511eb8fdcf1a58e05cb4278752f831a9d87e5dd
6
+ metadata.gz: bd65623f8475906b5519177ee5ab518fc51111b0565c7fb8c3a904d92e0ffd1a4ed1e2fb3927fb82bfdd3cb94039645a5d40f383aabdb79805270cef364d7897
7
+ data.tar.gz: 7c1d0fc7b244523bf63900b5a2d5c3b2e427a7d224e3bdd10697f772d728a333f5d5a17c4a86bf5a2806e57af0b25a71b732d084dada16e8fa6c96f8b3670dec
data/Rakefile CHANGED
@@ -14,7 +14,7 @@ GemHadar do
14
14
  map(&File.method(:basename))
15
15
  test_dir 'tests'
16
16
  ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', '.rvmrc', '.AppleDouble',
17
- 'tags', '.bundle', '.DS_Store', '.byebug_history'
17
+ 'tags', '.bundle', '.DS_Store', '.byebug_history', '.yardoc', 'doc'
18
18
  package_ignore '.gitignore', 'VERSION'
19
19
  readme 'README.md'
20
20
  licenses << 'GPL-2.0'
data/bin/code_comment CHANGED
@@ -11,7 +11,7 @@
11
11
  # descriptions, parameters, return values, and exceptions.
12
12
  #
13
13
  # Requires:
14
- # - Git repository with Ruby files in lib/, spec/, or test/ directories
14
+ # - Git repository with Ruby files in lib/, spec/, or tests/ directories
15
15
  # - Ollama server running locally or accessible via OLLAMA_URL / OLLAMA_HOST
16
16
  # - Configuration files in ~/.config/code_comment/
17
17
  # - system.txt: System prompt for LLM
@@ -111,14 +111,18 @@ def build_method_prompt(construct_type, construct, context)
111
111
 
112
112
  Format requirements:
113
113
 
114
- 1. Focus on providing a description of the %{construct_type}'s purpose
114
+ 1. focus on providing a description of the %{construct_type}'s purpose
115
115
  without including any code snippets.
116
- 2. You should omit the @raise if you are not sure.
117
- 3. Never use `, `ruby, ```, ```ruby in your response.
118
- 4. Never add any other remarks or explanation to your response.
119
- 5. Start each line of your comment with a single # character.
116
+ 2. **always** output just the line comments starting each with a single #
117
+ character.
118
+ 3. **never** output any executable ruby code like class or module
119
+ definitions, or method definitions or other code outside of such
120
+ comments.
121
+ 4. you should omit the @raise if you are not sure.
122
+ 5. never use `, `ruby, ```, ```ruby in your response.
123
+ 6. never add any other remarks or explanation to your response.
120
124
  EOT
121
- $config.read('method-prompt.txt', default: default_prompt) % {
125
+ $config_dir.read('method-prompt.txt', default: default_prompt) % {
122
126
  construct_type:, construct:, context:,
123
127
  }
124
128
  end
@@ -146,15 +150,18 @@ def build_class_module_prompt(construct_type, construct, context)
146
150
 
147
151
  Format requirements:
148
152
 
149
- 1. Focus on providing a description of the %{construct_type}'s purpose
153
+ 1. focus on providing a description of the %{construct_type}'s purpose
150
154
  without including any code snippets.
151
- 2. Include @example tag if there are notable usage patterns for this
152
- construct.
153
- 3. Never use `, `ruby, ```, ```ruby in your response.
154
- 4. Never add any other remarks or explanation to your response.
155
- 5. Start each line of your comment with a single # character.
155
+ 2. **always** output just the line comments starting each with a single #
156
+ character.
157
+ 3. **never** output any executable ruby code like class or module
158
+ definitions, or method definitions or other code outside of such
159
+ comments.
160
+ 4. you should omit the @raise if you are not sure.
161
+ 5. never use `, `ruby, ```, ```ruby in your response.
162
+ 6. never add any other remarks or explanation to your response.
156
163
  EOT
157
- $config.read('class-module-prompt.txt', default: default_prompt) % {
164
+ $config_dir.read('class-module-prompt.txt', default: default_prompt) % {
158
165
  construct_type:, construct:, context:,
159
166
  }
160
167
  end
@@ -171,7 +178,9 @@ def build_prompt(construct_type, construct, context)
171
178
  end
172
179
 
173
180
  filename_linenumber = ARGV.shift or fail "require file_name as second argument"
174
- $config = Utils::ConfigDir.new('code_comment', env_var: 'XDG_CONFIG_HOME')
181
+ $config = Utils::ConfigFile.new
182
+ $config.configure_from_paths
183
+ $config_dir = Utils::ConfigDir.new('code_comment', env_var: 'XDG_CONFIG_HOME')
175
184
  base_url = ENV['OLLAMA_URL'] || 'http://%s' % ENV.fetch('OLLAMA_HOST')
176
185
  model = ENV.fetch('OLLAMA_MODEL', 'llama3.1')
177
186
  construct, construct_type = fetch_construct(filename_linenumber)
@@ -185,15 +194,17 @@ default_context = ContextSpook.generate_context do
185
194
  file "README.md", tags: %w[ documentation ]
186
195
 
187
196
  # Auto-discover files using globs
188
- %w[ lib spec test ].each do |dir|
197
+ $config.code_comment.code_globs.each do |dir_glob|
198
+ dir = dir_glob.sub(%r(/.*), '').full? || 'none'
189
199
  namespace dir do
190
- Dir["#{dir}/**/*.rb"].each do |filename|
191
- file filename, tags: %w[ ruby ]
200
+ Dir[dir_glob].each do |filename|
201
+ file filename
192
202
  end
193
203
  end
194
204
  end
195
205
  end
196
206
  end
207
+
197
208
  context = if File.exist?(context_filename)
198
209
  STDERR.puts "Using context from #{context_filename.inspect}."
199
210
  ContextSpook.generate_context(context_filename)
@@ -223,7 +234,7 @@ default_system = <<~EOT
223
234
  * @example usage patterns when helpful
224
235
  * Avoid version information (@since)
225
236
  EOT
226
- system = $config.read('system.txt', default: default_system)
237
+ system = $config_dir.read('system.txt', default: default_system)
227
238
 
228
239
  prompt = build_prompt(construct_type, construct, context)
229
240
 
@@ -238,10 +249,10 @@ default_options = JSON(
238
249
  min_p: 0.1,
239
250
  )
240
251
 
241
- client_config = Client::Config.load_from_json $config + 'client.json'
252
+ client_config = Client::Config.load_from_json $config_dir + 'client.json'
242
253
  client_config.base_url = base_url
243
254
  ollama = Client.configure_with(client_config)
244
- options = JSON.parse($config.read('options.json', default: default_options))
255
+ options = JSON.parse($config_dir.read('options.json', default: default_options))
245
256
 
246
257
  if ENV['DEBUG'].to_i == 1
247
258
  File.open('debug.log', ?w) do |log|
data/bin/yaml_check CHANGED
@@ -24,6 +24,8 @@
24
24
  # DEBUG=1 ./yaml_check data.yaml
25
25
  #
26
26
 
27
+ require 'yaml'
28
+
27
29
  format = -> s {
28
30
  if /^\((?<f>[^)]+)\):\ (?<m>.*?) at line (?<l>\d+) column (?<c>\d+)/ =~ s
29
31
  [ f, l, c, m ] * ?:
@@ -2,6 +2,21 @@ require 'pathname'
2
2
  require 'stringio'
3
3
 
4
4
  module Utils
5
+ # A configuration directory manager that handles path resolution and file
6
+ # operations within a specified directory structure.
7
+ #
8
+ # This class provides functionality for managing configuration directories by
9
+ # deriving paths based on a root directory and name, and offering methods to
10
+ # read files with optional default values and block handling. It supports
11
+ # environment variable-based root path resolution and uses Pathname for
12
+ # robust path manipulation.
13
+ #
14
+ # @example
15
+ # config_dir = Utils::ConfigDir.new('myapp')
16
+ # config_dir.to_s # => returns the string representation of the configuration directory path
17
+ # config_dir.join('config.txt') # => returns a Pathname object for the joined path
18
+ # config_dir.read('settings.rb') # => reads and returns the content of 'settings.rb' or nil if not found
19
+ # config_dir.read('missing.txt', default: 'default content') # => returns 'default content' if file is missing
5
20
  class ConfigDir
6
21
  # Initializes a new ConfigDir instance with the specified name and optional
7
22
  # root path or environment variable.
@@ -1,5 +1,11 @@
1
1
  require 'tins'
2
2
 
3
+ # Configuration file manager for Utils library.
4
+ #
5
+ # This class provides functionality for loading, parsing, and managing
6
+ # configuration settings from multiple sources. It supports DSL-style
7
+ # configuration blocks and integrates with various utility components to
8
+ # provide centralized configuration management.
3
9
  class Utils::ConfigFile
4
10
  class << self
5
11
  attr_accessor :config_file_paths
@@ -12,6 +18,12 @@ class Utils::ConfigFile
12
18
 
13
19
  include DSLKit::Interpreter
14
20
 
21
+ # Error raised when configuration file parsing fails.
22
+ #
23
+ # This exception is specifically designed to be thrown when issues occur
24
+ # during the parsing or processing of configuration files within the Utils
25
+ # library. It inherits from StandardError, making it a standard Ruby
26
+ # exception that can be caught and handled appropriately by calling code.
15
27
  class ConfigFileError < StandardError; end
16
28
 
17
29
  # The initialize method sets up a new instance of the class.
@@ -76,6 +88,12 @@ class Utils::ConfigFile
76
88
  self
77
89
  end
78
90
 
91
+ # Base class for defining configuration blocks with DSL accessors.
92
+ #
93
+ # This class provides a foundation for creating configuration classes that
94
+ # support dynamic attribute definition through DSL-style accessor methods. It
95
+ # includes functionality for registering configuration settings and
96
+ # generating Ruby code representations of the configuration state.
79
97
  class BlockConfig
80
98
  class << self
81
99
  # The inherited method extends the module with DSL accessor functionality
@@ -158,11 +176,17 @@ class Utils::ConfigFile
158
176
  end
159
177
  end
160
178
 
179
+ # A configuration class for test execution settings.
180
+ #
181
+ # This class manages the configuration options related to running tests,
182
+ # specifically supporting different test frameworks and defining which
183
+ # directories should be included in test discovery and execution.
161
184
  class Probe < BlockConfig
162
185
  # The config method sets up a configuration option for the test framework.
163
186
  #
164
187
  # This method defines a configuration parameter that specifies which test
165
- # framework should be used, allowing for flexible test execution environments.
188
+ # framework should be used, allowing for flexible test execution
189
+ # environments.
166
190
  #
167
191
  # @param name [ Symbol ] the name of the configuration option
168
192
  # @param value [ Object ] the value to set for the configuration option
@@ -221,6 +245,13 @@ class Utils::ConfigFile
221
245
  @probe ||= Probe.new
222
246
  end
223
247
 
248
+ # A configuration class for file system operations.
249
+ #
250
+ # This class manages the configuration settings for searching and discovering
251
+ # files and directories while filtering out unwanted entries based on
252
+ # configured patterns. It provides functionality to define which directories
253
+ # should be pruned and which files should be skipped during file system
254
+ # operations.
224
255
  class FileFinder < BlockConfig
225
256
  # The prune? method checks if a basename matches any of the configured
226
257
  # prune directories.
@@ -254,6 +285,13 @@ class Utils::ConfigFile
254
285
  end
255
286
  end
256
287
 
288
+ # A configuration class for search operations.
289
+ #
290
+ # This class manages the configuration settings for searching files and
291
+ # directories while filtering out unwanted entries based on configured
292
+ # patterns. It inherits from FileFinder and provides functionality to define
293
+ # which directories should be pruned and which files should be skipped during
294
+ # search processes.
257
295
  class Search < FileFinder
258
296
  # The prune_dirs method configures the pattern for identifying directories
259
297
  # to be pruned during file system operations.
@@ -299,6 +337,12 @@ class Utils::ConfigFile
299
337
  @search ||= Search.new
300
338
  end
301
339
 
340
+ # A configuration class for file discovery operations.
341
+ #
342
+ # This class manages the configuration settings for discovering files and directories
343
+ # while filtering out unwanted entries based on configured patterns. It inherits from
344
+ # FileFinder and provides functionality to define which directories should be pruned
345
+ # and which files should be skipped during discovery processes.
302
346
  class Discover < FileFinder
303
347
  # The prune_dirs method configures the pattern for identifying directories
304
348
  # to be pruned during file system operations.
@@ -361,6 +405,13 @@ class Utils::ConfigFile
361
405
  @discover ||= Discover.new
362
406
  end
363
407
 
408
+ # A configuration class for file system scope operations.
409
+ #
410
+ # This class manages the configuration settings for defining which files and
411
+ # directories should be included or excluded during file system traversals
412
+ # and searches. It inherits from FileFinder and provides pattern matching
413
+ # capabilities for pruning directories and skipping specific files based on
414
+ # configured regular expressions.
364
415
  class Scope < FileFinder
365
416
  # The prune_dirs method configures the pattern for identifying directories
366
417
  # to be pruned during file system operations.
@@ -404,6 +455,12 @@ class Utils::ConfigFile
404
455
  @scope ||= Scope.new
405
456
  end
406
457
 
458
+ # A configuration class for whitespace handling operations.
459
+ #
460
+ # This class manages the configuration options related to removing or modifying
461
+ # trailing whitespace in files. It provides functionality to define patterns for
462
+ # pruning directories and skipping specific files during whitespace processing,
463
+ # ensuring that only relevant files are affected by space-stripping operations.
407
464
  class StripSpaces < FileFinder
408
465
  # The prune_dirs method configures the pattern for directory names that
409
466
  # should be pruned.
@@ -448,6 +505,12 @@ class Utils::ConfigFile
448
505
  @strip_spaces ||= StripSpaces.new
449
506
  end
450
507
 
508
+ # SSH tunnel configuration manager
509
+ #
510
+ # Provides functionality for configuring and managing SSH tunnels with support for
511
+ # different terminal multiplexers like tmux and screen. Allows setting up tunnel
512
+ # specifications with local and remote address/port combinations, handling
513
+ # environment variables, and managing copy/paste functionality for tunnel sessions.
451
514
  class SshTunnel < BlockConfig
452
515
  # The terminal_multiplexer method configures the terminal multiplexer
453
516
  # setting.
@@ -472,8 +535,6 @@ class Utils::ConfigFile
472
535
 
473
536
  # The initialize method sets up the instance by calling the superclass
474
537
  # constructor and assigning the terminal multiplexer configuration.
475
- #
476
- # @param terminal_multiplexer [ Object ] the terminal multiplexer to be assigned
477
538
  def initialize
478
539
  super
479
540
  self.terminal_multiplexer = terminal_multiplexer
@@ -540,6 +601,12 @@ class Utils::ConfigFile
540
601
  end
541
602
  end
542
603
 
604
+ # Manages the copy/paste functionality configuration for SSH tunnels.
605
+ #
606
+ # This class handles the setup and configuration of copy/paste capabilities
607
+ # within SSH tunnel sessions, allowing users to define network addresses,
608
+ # ports, and other parameters needed for establishing and managing
609
+ # copy/paste connections through SSH tunnels.
543
610
  class CopyPaste < BlockConfig
544
611
  # The bind_address method configures the network address to which the
545
612
  # server will bind for incoming connections.
@@ -614,6 +681,17 @@ class Utils::ConfigFile
614
681
  self.config_settings << :copy_paste
615
682
  end
616
683
 
684
+ # The ssh_tunnel method provides access to an SSH tunnel configuration instance.
685
+ #
686
+ # This method returns the existing SSH tunnel configuration object if one has
687
+ # already been created, or initializes and returns a new SSH tunnel
688
+ # configuration instance if no instance exists. If a block is provided, it
689
+ # will be passed to the SSH tunnel configuration constructor when creating a
690
+ # new instance.
691
+ #
692
+ # @param block [ Proc ] optional block to configure the SSH tunnel object
693
+ #
694
+ # @return [ Utils::ConfigFile::SshTunnel ] an SSH tunnel configuration instance
617
695
  def ssh_tunnel(&block)
618
696
  if block
619
697
  @ssh_tunnel = SshTunnel.new(&block)
@@ -621,6 +699,12 @@ class Utils::ConfigFile
621
699
  @ssh_tunnel ||= SshTunnel.new
622
700
  end
623
701
 
702
+ # A configuration class for editor settings.
703
+ #
704
+ # This class manages the configuration options related to editing operations,
705
+ # specifically focusing on Vim editor integration. It provides functionality
706
+ # to configure the path to the Vim executable and default arguments used when
707
+ # invoking the editor.
624
708
  class Edit < BlockConfig
625
709
  # The vim_path method determines the path to the vim executable.
626
710
  #
@@ -650,6 +734,12 @@ class Utils::ConfigFile
650
734
  @edit ||= Edit.new
651
735
  end
652
736
 
737
+ # A configuration class for file classification settings.
738
+ #
739
+ # This class manages the configuration options related to classifying files
740
+ # by type or category. It provides functionality to define path shifting
741
+ # behavior and prefix handling for determining how file paths should be
742
+ # categorized during classification operations.
653
743
  class Classify < BlockConfig
654
744
  # The shift_path_by_default method configuration accessor
655
745
  #
@@ -687,6 +777,12 @@ class Utils::ConfigFile
687
777
  @classify ||= Classify.new
688
778
  end
689
779
 
780
+ # A configuration class for directory synchronization settings.
781
+ #
782
+ # This class manages the configuration options related to synchronizing
783
+ # directories using rsync. It provides functionality to define patterns for
784
+ # skipping certain paths during synchronization operations, making it easy to
785
+ # exclude temporary, cache, or version control files from being synced.
690
786
  class SyncDir < BlockConfig
691
787
  # The skip_path method configures a regular expression pattern for skipping
692
788
  # paths.
@@ -730,6 +826,33 @@ class Utils::ConfigFile
730
826
  @sync_dir ||= SyncDir.new
731
827
  end
732
828
 
829
+ # A configuration class for code comment settings.
830
+ #
831
+ # This class manages the configuration options related to generating YARD
832
+ # documentation for Ruby source code. It provides access to glob patterns
833
+ # that define which files should be considered when generating code comments.
834
+ class CodeComment < BlockConfig
835
+ dsl_accessor :code_globs, 'lib/**/*.rb', 'spec/**/*.rb', 'tests/**/*rb'
836
+ end
837
+
838
+ # The code_comment method provides access to a CodeComment configuration
839
+ # instance.
840
+ #
841
+ # This method returns the existing CodeComment instance if one has already
842
+ # been created, or initializes and returns a new CodeComment instance if no
843
+ # instance exists. If a block is provided, it will be passed to the
844
+ # CodeComment constructor when creating a new instance.
845
+ #
846
+ # @param block [ Proc ] optional block to configure the CodeComment object
847
+ #
848
+ # @return [ Utils::ConfigFile::CodeComment ] a CodeComment configuration instance
849
+ def code_comment(&block)
850
+ if block
851
+ @code_comment = CodeComment.new(&block)
852
+ end
853
+ @code_comment ||= CodeComment.new
854
+ end
855
+
733
856
  # The to_ruby method generates a Ruby configuration string by collecting
734
857
  # configuration data from various components and combining them into a
735
858
  # single formatted output.
data/lib/utils/editor.rb CHANGED
@@ -3,6 +3,19 @@ require 'rbconfig'
3
3
  require 'pstree'
4
4
 
5
5
  module Utils
6
+ # An editor interface for interacting with Vim server instances.
7
+ #
8
+ # This class provides functionality for managing Vim editor sessions through
9
+ # server connections, enabling features like remote file editing, window
10
+ # management, and server state monitoring. It handles communication with
11
+ # running Vim instances and supports various configuration options for
12
+ # customizing the editing experience.
13
+ #
14
+ # @example
15
+ # editor = Utils::Editor.new
16
+ # editor.edit('file.rb')
17
+ # editor.activate
18
+ # editor.stop
6
19
  class Editor
7
20
  # The initialize method sets up a new editor instance with default
8
21
  # configuration.
@@ -11,7 +24,8 @@ module Utils
11
24
  # flag, pause duration, and server name. It also loads the configuration
12
25
  # file and assigns the edit configuration section to the instance.
13
26
  #
14
- # @param block [ Proc ] optional block to be executed after initialization
27
+ # @yield |editor| optional block to be executed after initialization with
28
+ # self as argument.
15
29
  #
16
30
  # @return [ Utils::Editor ] a new editor instance configured with default settings
17
31
  def initialize
@@ -41,10 +55,14 @@ module Utils
41
55
  name.upcase
42
56
  end
43
57
 
44
- # The pause_duration method gets or sets the pause duration value.
58
+ # The pause_duration method provides access to the duration value used for
59
+ # pausing operations.
45
60
  #
46
- # @return [ Integer ] the current pause duration value
47
- # @param value [ Integer ] the new pause duration value to set
61
+ # This method returns the current value of the pause duration attribute,
62
+ # which controls how long certain operations should wait or pause between
63
+ # actions.
64
+ #
65
+ # @return [ Integer, Float ] the current pause duration value in seconds
48
66
  attr_accessor :pause_duration
49
67
 
50
68
  # The wait method gets the wait status.
data/lib/utils/finder.rb CHANGED
@@ -4,6 +4,18 @@ require 'digest/md5'
4
4
  require 'fileutils'
5
5
  require 'mize'
6
6
 
7
+ # A class for finding and searching files with configurable patterns and
8
+ # filters.
9
+ #
10
+ # This class provides functionality for traversing file systems to locate files
11
+ # based on various criteria including file extensions, directory pruning, and
12
+ # pattern matching. It supports both indexed and direct search approaches to
13
+ # optimize performance when dealing with large codebases or frequently accessed
14
+ # file sets.
15
+ #
16
+ # @example
17
+ # finder = Utils::Finder.new(args: { l: true }, roots: ['.'])
18
+ # finder.search
7
19
  class Utils::Finder
8
20
  include Tins::Find
9
21
  include Utils::Patterns
data/lib/utils/grepper.rb CHANGED
@@ -1,10 +1,27 @@
1
1
  require 'term/ansicolor'
2
2
 
3
+ # A class for searching and matching text patterns within files.
4
+ #
5
+ # This class provides functionality to search through file systems for content
6
+ # matching specified patterns, with support for various output formats and
7
+ # filtering options. It handles directory pruning, file skipping, and different
8
+ # types of pattern matching including regular expressions and fuzzy matching.
9
+ #
10
+ # @example
11
+ # grepper = Utils::Grepper.new(args: { l: true }, roots: ['.'])
12
+ # grepper.search
3
13
  class Utils::Grepper
4
14
  include Tins::Find
5
15
  include Utils::Patterns
6
16
  include Term::ANSIColor
7
17
 
18
+ # A queue implementation with size limitation.
19
+ #
20
+ # @example queue = Utils::Grepper::Queue.new(5) queue << "item1" queue <<
21
+ # "item2" # ... queue.data # => [ "item1", "item2", ... ]
22
+ #
23
+ # The Queue class provides a fixed-size buffer for storing objects. When the
24
+ # maximum size is exceeded, the oldest item is automatically removed.
8
25
  class Queue
9
26
  # The initialize method sets up a new instance with the specified maximum
10
27
  # size and empty data array.
data/lib/utils/irb.rb CHANGED
@@ -9,7 +9,19 @@ $editor = Utils::Editor.new
9
9
  $pager = ENV['PAGER'] || 'less -r'
10
10
 
11
11
  module Utils
12
+ # A module that extends Ruby's core classes with additional utility methods
13
+ # for interactive development.
14
+ #
15
+ # Provides enhanced functionality for IRB sessions through method extensions
16
+ # on Object, String, and Regexp classes. Includes features like improved
17
+ # pattern matching, shell command integration, file I/O operations,
18
+ # performance measurement tools, and developer productivity enhancements.
12
19
  module IRB
20
+ # A module that extends Regexp functionality with additional pattern
21
+ # matching and display capabilities.
22
+ #
23
+ # Provides enhanced regexp operations including match highlighting and
24
+ # shell command integration.
13
25
  module Shell
14
26
  require 'fileutils'
15
27
  include FileUtils
@@ -223,6 +235,12 @@ module Utils
223
235
  end.compact.sort!
224
236
  end
225
237
 
238
+ # Base class for wrapping objects with descriptive metadata.
239
+ #
240
+ # This class provides a foundation for creating wrapper objects that
241
+ # associate descriptive information with underlying objects. It handles
242
+ # name conversion and provides common methods for accessing and comparing
243
+ # wrapped objects.
226
244
  class WrapperBase
227
245
  include Comparable
228
246
 
@@ -293,6 +311,15 @@ module Utils
293
311
  end
294
312
  end
295
313
 
314
+ # A wrapper class for Ruby method objects that provides enhanced
315
+ # introspection and display capabilities.
316
+ #
317
+ # This class extends WrapperBase to create specialized wrappers for Ruby
318
+ # method objects, offering detailed information about methods including
319
+ # their source location, arity, and owner. It facilitates interactive
320
+ # exploration of Ruby methods in environments like IRB by providing
321
+ # structured access to method metadata and enabling sorting and
322
+ # comparison operations based on method descriptions.
296
323
  class MethodWrapper < WrapperBase
297
324
  # The initialize method sets up a new instance with the specified
298
325
  # object, method name, and module flag.
@@ -356,6 +383,15 @@ module Utils
356
383
  end
357
384
  end
358
385
 
386
+ # A wrapper class for Ruby constant objects that provides enhanced
387
+ # introspection and display capabilities.
388
+ #
389
+ # This class extends WrapperBase to create specialized wrappers for Ruby
390
+ # constant objects, offering detailed information about constants
391
+ # including their names and associated classes. It facilitates
392
+ # interactive exploration of Ruby constants in environments like IRB by
393
+ # providing structured access to constant metadata and enabling sorting
394
+ # and comparison operations based on constant descriptions.
359
395
  class ConstantWrapper < WrapperBase
360
396
  # The initialize method sets up a new instance with the provided object
361
397
  # and name.
@@ -667,6 +703,15 @@ module Utils
667
703
  end
668
704
  end
669
705
 
706
+ # A module that extends Regexp functionality with additional pattern
707
+ # matching and display capabilities.
708
+ #
709
+ # Provides enhanced regexp operations including match highlighting and
710
+ # shell command integration.
711
+ #
712
+ # @example
713
+ # /pattern/ # => regular expression object
714
+ # /pattern/.show_match("text") # => highlighted text match
670
715
  module Regexp
671
716
  # The show_match method evaluates a string against the receiver pattern
672
717
  # and highlights matching portions.
@@ -691,6 +736,11 @@ module Utils
691
736
  end
692
737
  end
693
738
 
739
+ # A module that extends String with additional utility methods for shell
740
+ # command piping and file writing operations.
741
+ #
742
+ # Provides convenient methods for executing shell commands on string
743
+ # content and securely writing strings to files.
694
744
  module String
695
745
  # The | method executes a shell command and returns its output.
696
746
  #
@@ -1,4 +1,12 @@
1
1
  module Utils
2
+ # A class for analyzing and retrieving git blame information for specific
3
+ # lines of code.
4
+ #
5
+ # This class provides functionality to initialize with a file path and line
6
+ # number, and then perform git blame operations to obtain information about
7
+ # when and by whom that specific line was last modified. It serves as a
8
+ # utility for developers to quickly access historical context for individual
9
+ # lines of code within their projects.
2
10
  class LineBlamer
3
11
  # Initializes a new LineBlamer instance to analyze source code line
4
12
  # information.
data/lib/utils/md5.rb CHANGED
@@ -1,6 +1,12 @@
1
1
  require 'digest/md5'
2
2
 
3
3
  module Utils
4
+ # MD5 module for computing MD5 hash digests of files.
5
+ #
6
+ # This module provides functionality for calculating MD5 hash digests of
7
+ # files using the Digest::MD5 library. It offers a convenient interface for
8
+ # computing hashes while handling file reading in chunks to optimize memory
9
+ # usage during the hashing process.
4
10
  module MD5
5
11
  class << self
6
12
  # The buffer_size accessor method provides read and write access to the
@@ -1,5 +1,19 @@
1
1
  module Utils
2
+ # A module that provides pattern matching functionality for file searching
3
+ # and text processing.
4
+ #
5
+ # It includes classes for different types of pattern matching including fuzzy
6
+ # matching and regular expression matching.
2
7
  module Patterns
8
+
9
+ # Base class for pattern matching implementations.
10
+ #
11
+ # This class serves as the foundation for various pattern matching
12
+ # strategies, providing common functionality for initializing patterns with
13
+ # character set filtering and case sensitivity options. It handles the core
14
+ # configuration and delegates specific matching behavior to subclasses.
15
+ #
16
+ # @abstract
3
17
  class Pattern
4
18
  # Initializes a new Pattern instance with the specified options.
5
19
  #
@@ -46,6 +60,19 @@ module Utils
46
60
  end
47
61
  end
48
62
 
63
+ # A fuzzy pattern matcher that performs partial string matching while
64
+ # preserving character order.
65
+ #
66
+ # This class implements a pattern matching strategy that allows for
67
+ # flexible matching of strings where the characters of the search pattern
68
+ # appear in sequence within the target string, but not necessarily
69
+ # consecutively. It is particularly useful for finding text patterns with
70
+ # potential typos or
71
+ # when only partial information about the target is available.
72
+ #
73
+ # @example
74
+ # fuzzy_pattern = FuzzyPattern.new(pattern: 'abc')
75
+ # fuzzy_pattern.match('a1b2c3') # => matches because 'a', 'b', and 'c' appear in order
49
76
  class FuzzyPattern < Pattern
50
77
  # Initializes a fuzzy pattern matcher by processing the pattern string
51
78
  # and compiling it into a regular expression.
@@ -70,6 +97,18 @@ module Utils
70
97
  end
71
98
  end
72
99
 
100
+ # A regular expression pattern matcher that performs exact string matching
101
+ # with optional case sensitivity.
102
+ #
103
+ # This class extends the base Pattern class to provide functionality for
104
+ # creating and using regular expression patterns. It compiles the provided
105
+ # pattern into a Regexp object that can be used for matching operations
106
+ # throughout the application. The pattern matching behavior is influenced
107
+ # by the case sensitivity configuration inherited from the parent class.
108
+ #
109
+ # @example
110
+ # regexp_pattern = RegexpPattern.new(pattern: 'foo', icase: true)
111
+ # regexp_pattern.match('FOO') # => matches because case insensitive
73
112
  class RegexpPattern < Pattern
74
113
  # Initializes a regular expression pattern matcher with the specified
75
114
  # options.
@@ -2,6 +2,12 @@ require 'unix_socks'
2
2
  require 'term/ansicolor'
3
3
 
4
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.
5
11
  class ProcessJob
6
12
  include Term::ANSIColor
7
13
 
@@ -125,7 +131,19 @@ module Utils
125
131
  end
126
132
  end
127
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.
128
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.
129
147
  class EnvProxy
130
148
  # The initialize method sets up a new instance with the provided server
131
149
  # object.
@@ -208,6 +226,13 @@ module Utils
208
226
  end
209
227
  end
210
228
 
229
+ # A probe server for managing and executing process jobs through Unix domain
230
+ # sockets.
231
+ #
232
+ # This class provides a mechanism for enqueueing and running process jobs in
233
+ # a distributed manner, using Unix domain sockets for communication. It
234
+ # maintains a queue of jobs, tracks their execution status, and provides an
235
+ # interactive interface for managing the server.
211
236
  class ProbeServer
212
237
  include Term::ANSIColor
213
238
 
@@ -276,13 +301,13 @@ module Utils
276
301
 
277
302
  annotate :shortcut
278
303
 
304
+ doc 'Display this help.'
305
+ shortcut :h
279
306
  # The help method displays a formatted list of available commands and their
280
307
  # descriptions.
281
308
  #
282
309
  # This method organizes and presents the documented commands along with their
283
310
  # shortcuts and descriptions in a formatted table layout for easy reference.
284
- doc 'Display this help.'
285
- shortcut :h
286
311
  def help
287
312
  docs = doc_annotations.sort_by(&:first)
288
313
  docs_size = docs.map { |a| a.first.size }.max
@@ -295,6 +320,8 @@ module Utils
295
320
  }
296
321
  end
297
322
 
323
+ doc 'Enqueue a new job with the argument array <args>.'
324
+ shortcut :e
298
325
  # The job_enqueue method adds a new process job to the execution queue.
299
326
  #
300
327
  # This method creates a process job instance with the provided arguments
@@ -302,8 +329,6 @@ module Utils
302
329
  # about the enqueued job through output messaging.
303
330
  #
304
331
  # @param args [ Array ] the command arguments to be executed by the process job
305
- doc 'Enqueue a new job with the argument array <args>.'
306
- shortcut :e
307
332
  def job_enqueue(args)
308
333
  job = ProcessJob.new(args:, probe_server: self)
309
334
  output_message " → #{job.inspect} enqueued.", type: :info
@@ -311,17 +336,19 @@ module Utils
311
336
  end
312
337
  alias enqueue job_enqueue
313
338
 
339
+ doc 'Quit the server.'
340
+ shortcut :q
314
341
  # The shutdown method terminates the probe server process immediately.
315
342
  #
316
343
  # This method outputs a warning message indicating that the server is being
317
344
  # shut down forcefully and then exits the program with status code 23.
318
- doc 'Quit the server.'
319
- shortcut :q
320
345
  def shutdown
321
346
  output_message "Server was shutdown down manually!", type: :info
322
347
  exit 23
323
348
  end
324
349
 
350
+ doc 'Repeat the job with <job_id> or the last, it will be assigned a new id, though.'
351
+ shortcut :r
325
352
  # The job_repeat method re-executes a previously run job from the history.
326
353
  #
327
354
  # This method takes a job identifier and attempts to find the corresponding
@@ -334,8 +361,6 @@ module Utils
334
361
  #
335
362
  # @return [ TrueClass, FalseClass ] true if the job was found and re-enqueued,
336
363
  # false otherwise
337
- doc 'Repeat the job with <job_id> or the last, it will be assigned a new id, though.'
338
- shortcut :r
339
364
  def job_repeat(job_id = @history.last)
340
365
  ProcessJob === job_id and job_id = job_id.id
341
366
  if old_job = @history.find { |job| job.id == job_id }
@@ -346,17 +371,18 @@ module Utils
346
371
  end
347
372
  end
348
373
 
374
+ doc 'List the history of run jobs.'
375
+ shortcut :l
349
376
  # The history_list method displays the list of previously executed jobs
350
377
  # from the server's history.
351
378
  #
352
379
  # This method outputs all completed jobs that have been processed by the probe server,
353
380
  # showing their identifiers and command arguments for review.
354
- doc 'List the history of run jobs.'
355
- shortcut :l
356
381
  def history_list
357
382
  output_message @history
358
383
  end
359
384
 
385
+ doc 'Clear the history of run jobs.'
360
386
  # The history_clear method clears all entries from the server's execution
361
387
  # history.
362
388
  #
@@ -365,12 +391,18 @@ module Utils
365
391
  # probe server.
366
392
  #
367
393
  # @return [ TrueClass ] always returns true after clearing the history
368
- doc 'Clear the history of run jobs.'
369
394
  def history_clear
370
395
  @history = []
371
396
  true
372
397
  end
373
398
 
399
+ # A wrapper class for environment variable management that logs operations.
400
+ #
401
+ # This class provides a transparent interface for accessing and modifying
402
+ # environment variables while recording these interactions. It delegates all
403
+ # method calls to an underlying object (typically ENV) but intercepts assignments
404
+ # to log the changes, enabling tracking of environment modifications during
405
+ # probe server operations.
374
406
  class LogWrapper < BasicObject
375
407
  # The initialize method sets up a new instance with the provided server
376
408
  # object and object.
@@ -1,4 +1,19 @@
1
1
  module Utils
2
+ # A class that represents an SSH tunnel specification for configuring network
3
+ # connections.
4
+ #
5
+ # This class parses and stores the configuration details for SSH tunnels,
6
+ # including local and remote address/port combinations. It provides methods
7
+ # to validate the specification, convert it to string or array
8
+ # representations, and access individual components of the tunnel
9
+ # configuration.
10
+ #
11
+ # @example
12
+ # spec = Utils::SshTunnelSpecification.new('localhost:8080:remote.host:22')
13
+ # spec.local_addr # => 'localhost'
14
+ # spec.local_port # => 8080
15
+ # spec.remote_addr # => 'remote.host'
16
+ # spec.remote_port # => 22
2
17
  class SshTunnelSpecification
3
18
  # Initializes a new SshTunnelSpecification instance by parsing the provided
4
19
  # specification string.
data/lib/utils/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Utils
2
2
  # Utils version
3
- VERSION = '0.73.1'
3
+ VERSION = '0.74.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:
@@ -1,5 +1,23 @@
1
1
  module Utils
2
+ # Extension module for adding source location functionality to objects.
3
+ #
4
+ # This module provides enhanced source location capabilities by extending
5
+ # objects with methods that can determine file paths and line numbers
6
+ # associated with method definitions, class references, or file-based
7
+ # locations. It supports parsing of various input formats including file:line
8
+ # syntax, class.method patterns, and provides convenient accessors for
9
+ # filename, line number, and range information through the source_location
10
+ # method.
2
11
  module Xt
12
+ # Extension module for adding source location functionality to objects.
13
+ #
14
+ # This module provides enhanced source location capabilities by extending
15
+ # objects with methods that can determine file paths and line numbers
16
+ # associated with method definitions, class references, or file-based
17
+ # locations. It supports parsing of various input formats including
18
+ # file:line syntax, class.method patterns, and provides convenient
19
+ # accessors for filename, line number, and range information through the
20
+ # source_location method.
3
21
  module SourceLocationExtension
4
22
  # Regular expression to match Ruby class method signatures
5
23
  # Matches patterns like "ClassName#method" or "ClassName.method"
data/lib/utils.rb CHANGED
@@ -1,5 +1,11 @@
1
1
  require 'tins/xt'
2
2
 
3
+ # The main Utils module serves as the primary namespace for the developer
4
+ # productivity command-line utilities gem.
5
+
6
+ # This module provides the core functionality and organization for the Utils
7
+ # library, which delivers a curated collection of command-line tools designed
8
+ # to streamline software development workflows and automate repetitive tasks.
3
9
  module Utils
4
10
  require 'utils/version'
5
11
  require 'utils/md5'
data/utils.gemspec CHANGED
@@ -1,9 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: utils 0.73.1 ruby lib
2
+ # stub: utils 0.74.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "utils".freeze
6
- s.version = "0.73.1".freeze
6
+ s.version = "0.74.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]
@@ -23,7 +23,7 @@ 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.0".freeze])
26
+ s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 2.1".freeze])
27
27
  s.add_development_dependency(%q<test-unit>.freeze, [">= 0".freeze])
28
28
  s.add_runtime_dependency(%q<unix_socks>.freeze, [">= 0".freeze])
29
29
  s.add_runtime_dependency(%q<webrick>.freeze, [">= 0".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.73.1
4
+ version: 0.74.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: '2.0'
18
+ version: '2.1'
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.0'
25
+ version: '2.1'
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: test-unit
28
28
  requirement: !ruby/object:Gem::Requirement