peeky 0.0.45 → 0.0.49
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/peeky/class_info.rb +40 -5
- data/lib/peeky/method_info.rb +14 -2
- data/lib/peeky/predicates/attr_reader_predicate.rb +1 -1
- data/lib/peeky/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aff77966760d7a7c6d692018aa18baa50188c6a7f22f989c6d5dda3805803568
|
4
|
+
data.tar.gz: fcc3b1211915afe38b6fa0cfa803813ea40c54a87d03893c1d8b816ea1188244
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52b00507cf58f9723d285c0405b7e96016fe51aa52b15b4a7a0eb60e03ce02ccbb226f60d22b9d005607064c03affb4ec67acc4c961675e1afc22170f01f93d5
|
7
|
+
data.tar.gz: 86804ade54bca766936cdddab08b04ca6c22a1a05e1845efa056a7538b4d44018a6933ea494e4c09406c31ce7ac6c7764928f7c13fdb212a568b2dce25959e00
|
data/lib/peeky/class_info.rb
CHANGED
@@ -17,6 +17,20 @@ module Peeky
|
|
17
17
|
@instance = instance
|
18
18
|
end
|
19
19
|
|
20
|
+
def to_h
|
21
|
+
{
|
22
|
+
class_name: class_name,
|
23
|
+
module_name: module_name,
|
24
|
+
class_full_name: class_full_name,
|
25
|
+
attr_accessor: accessors.map(&:name),
|
26
|
+
attr_reader: readers.map(&:name),
|
27
|
+
attr_writer: writers.map(&:name),
|
28
|
+
klass: methods_to_h(class_methods),
|
29
|
+
instance_public: methods_to_h(public_methods),
|
30
|
+
instance_private: methods_to_h(private_methods)
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
20
34
|
# rubocop:disable Metrics/AbcSize
|
21
35
|
def to_s
|
22
36
|
result = []
|
@@ -72,7 +86,13 @@ module Peeky
|
|
72
86
|
|
73
87
|
# Module name
|
74
88
|
def module_name
|
75
|
-
@module_name
|
89
|
+
return @module_name if defined? @module_name
|
90
|
+
|
91
|
+
@module_name = if class_full_name.include?('::')
|
92
|
+
class_full_name.to_s.gsub(/(.*)::.*/, '\1')
|
93
|
+
else
|
94
|
+
''
|
95
|
+
end
|
76
96
|
end
|
77
97
|
|
78
98
|
# Get a list of :attr_accessor on the class
|
@@ -218,7 +238,7 @@ module Peeky
|
|
218
238
|
end
|
219
239
|
|
220
240
|
def ruby_class_method_names
|
221
|
-
@ruby_class_method_names ||= instance.class.singleton_class.instance_methods(false).sort
|
241
|
+
@ruby_class_method_names ||= instance.class.methods(false).sort # singleton_class.instance_methods(false).sort
|
222
242
|
end
|
223
243
|
|
224
244
|
def ruby_instance_method_names
|
@@ -232,22 +252,37 @@ module Peeky
|
|
232
252
|
def ruby_class_methods
|
233
253
|
@ruby_class_methods ||= ruby_class_method_names.map { |method_name| instance.class.method(method_name) }
|
234
254
|
rescue StandardError => e
|
235
|
-
|
255
|
+
puts 'ruby_class_methods'
|
236
256
|
puts e
|
237
257
|
end
|
238
258
|
|
239
259
|
def ruby_private_methods
|
240
260
|
@ruby_private_methods ||= ruby_private_method_names.map { |method_name| instance.method(method_name) }
|
241
261
|
rescue StandardError => e
|
242
|
-
|
262
|
+
puts 'ruby_private_methods'
|
243
263
|
puts e
|
244
264
|
end
|
245
265
|
|
246
266
|
def ruby_instance_methods
|
247
267
|
@ruby_instance_methods ||= ruby_instance_method_names.map { |method_name| instance.method(method_name) }
|
248
268
|
rescue StandardError => e
|
249
|
-
|
269
|
+
puts 'ruby_instance_methods'
|
250
270
|
puts e
|
251
271
|
end
|
272
|
+
|
273
|
+
def methods_to_h(methods)
|
274
|
+
methods.map do |m|
|
275
|
+
{
|
276
|
+
name: m.name,
|
277
|
+
paramaters: m.parameters.map do |p|
|
278
|
+
{
|
279
|
+
name: p.name,
|
280
|
+
type: p.type,
|
281
|
+
default_value: p.default_value
|
282
|
+
}
|
283
|
+
end
|
284
|
+
}
|
285
|
+
end
|
286
|
+
end
|
252
287
|
end
|
253
288
|
end
|
data/lib/peeky/method_info.rb
CHANGED
@@ -94,15 +94,22 @@ module Peeky
|
|
94
94
|
return if minimalist_method.end_with?('=')
|
95
95
|
return unless optional?
|
96
96
|
|
97
|
+
# TODO: maybe I can use this technique instead and just read the source code
|
98
|
+
# file, line = @focal_method.source_location
|
99
|
+
|
97
100
|
tracer.enable do
|
101
|
+
# puts grab_source
|
98
102
|
# TODO: minimalist method should be able to handle class methods
|
99
103
|
@target_instance.instance_eval(minimalist_method) if @implementation_type == :method
|
100
104
|
@target_instance.class.instance_eval(minimalist_method) if @implementation_type == :class_method
|
101
|
-
rescue StandardError => e
|
105
|
+
rescue StandardError, LoadError # => e
|
102
106
|
# just print the error for now, we are only attempting to capture the
|
103
107
|
# first call, any errors inside the call cannot be dealt with and should
|
104
108
|
# not be re-raised
|
105
|
-
|
109
|
+
# red full stop
|
110
|
+
print "\e[31m.\e[0m"
|
111
|
+
# puts minimalist_method
|
112
|
+
# puts e.message
|
106
113
|
end
|
107
114
|
end
|
108
115
|
|
@@ -159,5 +166,10 @@ module Peeky
|
|
159
166
|
def writable?
|
160
167
|
@implementation_type == :attr_writer
|
161
168
|
end
|
169
|
+
|
170
|
+
def grab_source(limit = 10)
|
171
|
+
file, line = @focal_method.source_location
|
172
|
+
File.read(file).lines[line - 1, limit] if file && line
|
173
|
+
end
|
162
174
|
end
|
163
175
|
end
|
data/lib/peeky/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: peeky
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.49
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Cruwys
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -99,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
99
|
- !ruby/object:Gem::Version
|
100
100
|
version: '0'
|
101
101
|
requirements: []
|
102
|
-
rubygems_version: 3.2.
|
102
|
+
rubygems_version: 3.2.33
|
103
103
|
signing_key:
|
104
104
|
specification_version: 4
|
105
105
|
summary: Take a peek into your ruby classes and extract useful meta data
|