utils 0.89.1 → 0.91.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: 6bae48a704c2a4cf0b1ab2eaa4ef3e4fcae5d5e9c84fac4d3db59fbf03a5a24b
4
- data.tar.gz: b1a0bd4139042eb1b737d5646d0b65b1bb13234aaf87e82ff0a3351314beea51
3
+ metadata.gz: b149334df404d05b42629dc6e31b42ce256deabef017d1f9b32a51461b40ebee
4
+ data.tar.gz: 122023649023e483bfe83fd17aa46c0f91e49d2713d37ebf8c88c93a07ff276a
5
5
  SHA512:
6
- metadata.gz: 594e6c2ed20cd83ef59b979da3435b2ffcb1476913f52d2e1be5aa98667d0701fb737ee02cf2fd9ef764108afd50591aae0672fe5c69207635da55ed0f875a35
7
- data.tar.gz: fe480b916e4a10261ccc51bf2f523a1902a21bef89fd65f231e18e768146b4c4b64ef954a4d39bc6e2ebe9a1d062964d7162b1ad7fcc1fc390f5cccdf2cb6d2c
6
+ metadata.gz: c1a2369321ea4b7f972b7d84533304f72c8c5cf9bfbd88a2cce706f89ccc525be5847992f1909dfc8669a7eeeebad57f861cca47841c3186f72ad368a24fe0d1
7
+ data.tar.gz: c58b333681c637c655dc628635de013550385e2eb384db3d26925d88eb339ce1a559663e85c0d1177b3cb1ab70339b39a04b148997c6d5209b60e5d02fc2eccd
data/bin/probe CHANGED
@@ -117,16 +117,18 @@ def connect_server
117
117
  opts = $opts.subhash(*%w[n t]).each_with_object([]) { |(k, v), a|
118
118
  v.full? and a.concat [ "-#{k}", v ]
119
119
  }
120
- probe_client.enqueue opts + $args
120
+ args = opts + $args
121
+ args += %w[ -- ] + $testrunner_args unless $testrunner_args.empty?
122
+ probe_client.enqueue(args)
121
123
  exit
122
124
  end
123
125
  end
124
126
 
125
127
  $config = Utils::ConfigFile.new
126
128
  $config.configure_from_paths
127
- testrunner_args = []
129
+ $testrunner_args = []
128
130
  if i = ARGV.index('--')
129
- testrunner_args.concat ARGV[(i + 1)..-1]
131
+ $testrunner_args.concat ARGV[(i + 1)..-1]
130
132
  $args = ARGV[0...i]
131
133
  else
132
134
  $args = ARGV.dup
@@ -134,6 +136,10 @@ end
134
136
  $opts = go 'lct:n:C:s:h', $args
135
137
  $opts[?h] and usage
136
138
 
139
+ $args.freeze
140
+ $testrunner_args.freeze
141
+ $opts.freeze
142
+
137
143
  case
138
144
  when $opts[?l]
139
145
  start_server
@@ -156,11 +162,11 @@ when :rspec
156
162
  end
157
163
  end
158
164
  cmd 'ruby', '-I', $config.probe.include_dirs_argument, *rspec,
159
- *($args + testrunner_args)
165
+ *($args + $testrunner_args)
160
166
  when :'test-unit'
161
167
  if testname = $opts[?n]
162
168
  cmd 'ruby', '-I', $config.probe.include_dirs_argument,
163
- *($args + testrunner_args), '-n', testname
169
+ *($args + $testrunner_args), '-n', testname
164
170
  else
165
171
  $args = $args.inject([]) { |args, a|
166
172
  args.push(*File.directory?(a) ? Dir[File.join(a, ?*)] : a)
@@ -171,13 +177,13 @@ when :'test-unit'
171
177
  lf = Tins::LinesFile.for_filename(*sl)
172
178
  if testname = lf.match_backward(/def\s+(\S+?)(?:\(|\s*$)/).full?(:first)
173
179
  cmd 'ruby', '-I', $config.probe.include_dirs_argument,
174
- sl.filename, *testrunner_args, '-n', testname
180
+ sl.filename, *$testrunner_args, '-n', testname
175
181
  else
176
182
  warn "no test found before line #{sl.linenumber}"
177
183
  end
178
184
  else
179
185
  cmd 'ruby', '-I', $config.probe.include_dirs_argument,
180
- sl.filename, *testrunner_args
186
+ sl.filename, *$testrunner_args
181
187
  end
182
188
  end
183
189
  end
@@ -185,7 +191,7 @@ when :cucumber
185
191
  cucumber = find_cmd('cucumber')
186
192
  if linenumber = $opts[?n]
187
193
  cmd 'ruby', cucumber, '-r', $config.probe.include_dirs_argument, '-l',
188
- linenumber, *($args + testrunner_args)
194
+ linenumber, *($args + $testrunner_args)
189
195
  else
190
196
  $args = $args.map do |a|
191
197
  if Utils::Editor::FILE_LINENUMBER_REGEXP =~ a
@@ -195,6 +201,6 @@ when :cucumber
195
201
  end
196
202
  end
197
203
  cmd 'ruby', cucumber, '-r', $config.probe.include_dirs_argument,
198
- *($args + testrunner_args)
204
+ *($args + $testrunner_args)
199
205
  end
200
206
  end
@@ -79,7 +79,7 @@ class Utils::IRB::IRBServer
79
79
  else
80
80
  @logger.warn("Message for action #{message.action.inspect} not supported.")
81
81
  end
82
- rescue => e
82
+ rescue StandardError, SyntaxError => e
83
83
  @logger.error("#{self.class.name} caught #{e.class}: #{e} for #{message.to_json}.")
84
84
  end
85
85
  self
@@ -0,0 +1,32 @@
1
+ # A module that extends Regexp functionality with additional pattern
2
+ # matching and display capabilities.
3
+ #
4
+ # Provides enhanced regexp operations including match highlighting and
5
+ # shell command integration.
6
+ #
7
+ # @example
8
+ # /pattern/ # => regular expression object
9
+ # /pattern/.show_match("text") # => highlighted text match
10
+ module Utils::IRB::Regexp
11
+ # The show_match method evaluates a string against the receiver pattern
12
+ # and highlights matching portions.
13
+ #
14
+ # This method tests whether the provided string matches the pattern
15
+ # represented by the receiver. When a match is found, it applies the
16
+ # success proc to highlight the matched portion of the string. If no
17
+ # match is found, it applies the failure proc to indicate that no match
18
+ # was found.
19
+ #
20
+ # @param string [ String ] the string to be tested against the pattern
21
+ # @param success [ Proc ] a proc that processes the matched portion of the string
22
+ # @param failure [ Proc ] a proc that processes the "no match" indication
23
+ #
24
+ # @return [ String ] the formatted string with matched portions highlighted or a no match message
25
+ def show_match(
26
+ string,
27
+ success: -> s { Term::ANSIColor.green { s } },
28
+ failure: -> s { Term::ANSIColor.red { s } }
29
+ )
30
+ string =~ self ? "#{$`}#{success.($&)}#{$'}" : failure.("no match")
31
+ end
32
+ end
@@ -0,0 +1,183 @@
1
+ module Utils::IRB::Shell
2
+ # Base class for wrapping objects with descriptive metadata.
3
+ #
4
+ # This class provides a foundation for creating wrapper objects that
5
+ # associate descriptive information with underlying objects. It handles
6
+ # name conversion and provides common methods for accessing and comparing
7
+ # wrapped objects.
8
+ class WrapperBase
9
+ include Comparable
10
+
11
+ # The initialize method sets up the instance name by converting the
12
+ # input to a string representation.
13
+ #
14
+ # This method handles different input types by converting them to a
15
+ # string, prioritizing to_str over to_sym and falling back to to_s if
16
+ # neither is available.
17
+ #
18
+ # @param name [ Object ] the input name to be converted to a string
19
+ def initialize(name)
20
+ @name =
21
+ case
22
+ when name.respond_to?(:to_str)
23
+ name.to_str
24
+ when name.respond_to?(:to_sym)
25
+ name.to_sym.to_s
26
+ else
27
+ name.to_s
28
+ end
29
+ end
30
+
31
+ # The name reader method returns the value of the name instance
32
+ # variable.
33
+ #
34
+ # @return [ String] the value stored in the name instance variable
35
+ attr_reader :name
36
+
37
+ # The description reader method provides access to the description
38
+ # attribute.
39
+ #
40
+ # @return [ String, nil ] the description value or nil if not set
41
+ attr_reader :description
42
+
43
+ alias to_str description
44
+
45
+ alias inspect description
46
+
47
+ alias to_s description
48
+
49
+ # The == method assigns a new name value to the instance variable.
50
+ #
51
+ # @param name [ Object ] the name value to be assigned
52
+ #
53
+ # @return [ Object ] returns the assigned name value
54
+ def ==(name)
55
+ @name = name
56
+ end
57
+
58
+ alias eql? ==
59
+
60
+ # The hash method returns the hash value of the name attribute.
61
+ #
62
+ # @return [ Integer ] the hash value used for object identification
63
+ def hash
64
+ @name.hash
65
+ end
66
+
67
+ # The <=> method compares the names of two objects for sorting purposes.
68
+ #
69
+ # @param other [ Object ] the other object to compare against
70
+ #
71
+ # @return [ Integer ] -1 if this object's name is less than the other's,
72
+ # 0 if they are equal, or 1 if this object's name is greater than the other's
73
+ def <=>(other)
74
+ @name <=> other.name
75
+ end
76
+ end
77
+
78
+ # A wrapper class for Ruby constant objects that provides enhanced
79
+ # introspection and display capabilities.
80
+ #
81
+ # This class extends WrapperBase to create specialized wrappers for Ruby
82
+ # constant objects, offering detailed information about constants
83
+ # including their names and associated classes. It facilitates
84
+ # interactive exploration of Ruby constants in environments like IRB by
85
+ # providing structured access to constant metadata and enabling sorting
86
+ # and comparison operations based on constant descriptions.
87
+ class ConstantWrapper < WrapperBase
88
+ # The initialize method sets up a new instance with the provided object
89
+ # and name.
90
+ #
91
+ # This method configures the instance by storing a reference to the
92
+ # object's class and creating a description string that combines the
93
+ # name with the class name.
94
+ #
95
+ # @param obj [ Object ] the object whose class will be referenced
96
+ # @param name [ String ] the name to be used in the description
97
+ #
98
+ # @return [ Utils::Patterns::Pattern ] a new pattern instance configured with the provided arguments
99
+ def initialize(obj, name)
100
+ super(name)
101
+ @klass = obj.class
102
+ @description = "#@name:#@klass"
103
+ end
104
+
105
+ # The klass reader method provides access to the class value stored in the instance.
106
+ #
107
+ # @return [ Object ] the class value
108
+ attr_reader :klass
109
+ end
110
+
111
+
112
+ # A wrapper class for Ruby method objects that provides enhanced
113
+ # introspection and display capabilities.
114
+ #
115
+ # This class extends WrapperBase to create specialized wrappers for Ruby
116
+ # method objects, offering detailed information about methods including
117
+ # their source location, arity, and owner. It facilitates interactive
118
+ # exploration of Ruby methods in environments like IRB by providing
119
+ # structured access to method metadata and enabling sorting and
120
+ # comparison operations based on method descriptions.
121
+ class MethodWrapper < WrapperBase
122
+ # The initialize method sets up a new instance with the specified
123
+ # object, method name, and module flag.
124
+ #
125
+ # This method creates and configures a new instance by storing the
126
+ # method object and its description, handling both instance methods and
127
+ # regular methods based on the module flag parameter.
128
+ #
129
+ # @param obj [ Object ] the object from which to retrieve the method
130
+ # @param name [ String ] the name of the method to retrieve
131
+ # @param modul [ TrueClass, FalseClass ] flag indicating whether to retrieve an instance method
132
+ def initialize(obj, name, modul)
133
+ super(name)
134
+ @wrapped_method = modul ? obj.instance_method(name) : obj.method(name)
135
+ @description = @wrapped_method.description(style: :namespace)
136
+ end
137
+
138
+ # The method reader returns the method object associated with the
139
+ # instance.
140
+ attr_reader :wrapped_method
141
+
142
+ # The owner method retrieves the owner of the method object.
143
+ #
144
+ # This method checks if the wrapped method object responds to the owner
145
+ # message and returns the owner if available, otherwise it returns nil.
146
+ #
147
+ # @return [ Object, nil ] the owner of the method or nil if not applicable
148
+ def owner
149
+ @wrapped_method.respond_to?(:owner) ? @wrapped_method.owner : nil
150
+ end
151
+
152
+ # The arity method returns the number of parameters expected by the method.
153
+ #
154
+ # @return [ Integer ] the number of required parameters for the method
155
+ def arity
156
+ @wrapped_method.arity
157
+ end
158
+
159
+ # The source_location method retrieves the file path and line number
160
+ # where the method is defined.
161
+ #
162
+ # This method accesses the underlying source location information for
163
+ # the method object, returning an array that contains the filename and
164
+ # line number of the method's definition.
165
+ #
166
+ # @return [ Array<String, Integer> ] an array containing the filename and line number
167
+ # where the method is defined, or nil if the location cannot be determined
168
+ def source_location
169
+ @wrapped_method.source_location
170
+ end
171
+
172
+ # The <=> method compares the descriptions of two objects for ordering
173
+ # purposes.
174
+ #
175
+ # @param other [ Object ] the other object to compare against
176
+ #
177
+ # @return [ Integer ] -1 if this object's description is less than the other's,
178
+ # 0 if they are equal, or 1 if this object's description is greater than the other's
179
+ def <=>(other)
180
+ @description <=> other.description
181
+ end
182
+ end
183
+ end