utils 0.90.0 → 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 +4 -4
- data/lib/utils/irb/irb_server.rb +1 -1
- data/lib/utils/irb/regexp.rb +32 -0
- data/lib/utils/irb/shell/wrappers.rb +183 -0
- data/lib/utils/irb/shell.rb +632 -0
- data/lib/utils/irb/string.rb +36 -0
- data/lib/utils/irb.rb +4 -865
- data/lib/utils/line_formatter.rb +12 -6
- data/lib/utils/version.rb +1 -1
- data/lib/utils/xt/source_location_extension.rb +13 -4
- data/lib/utils.rb +19 -1
- data/utils.gemspec +4 -4
- metadata +9 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b149334df404d05b42629dc6e31b42ce256deabef017d1f9b32a51461b40ebee
|
|
4
|
+
data.tar.gz: 122023649023e483bfe83fd17aa46c0f91e49d2713d37ebf8c88c93a07ff276a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c1a2369321ea4b7f972b7d84533304f72c8c5cf9bfbd88a2cce706f89ccc525be5847992f1909dfc8669a7eeeebad57f861cca47841c3186f72ad368a24fe0d1
|
|
7
|
+
data.tar.gz: c58b333681c637c655dc628635de013550385e2eb384db3d26925d88eb339ce1a559663e85c0d1177b3cb1ab70339b39a04b148997c6d5209b60e5d02fc2eccd
|
data/lib/utils/irb/irb_server.rb
CHANGED
|
@@ -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
|