peeky 0.0.42 → 0.0.43

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: 920d6f10ed0e11acad5844cc60e290ba9e7ee85e27e801cf766e6934e6e3ea06
4
- data.tar.gz: 4637e61e368dba0a5c4a9c3e8b0e8ff058b11c939ea848040eeff4a71a15e627
3
+ metadata.gz: a5ace1c867116904f98e261077b746cd8d2621f657a391e79c80f3f57edf4583
4
+ data.tar.gz: 195ab81abb7ab1198c19613c4fe2f4e730fd2b6a6c2654938396ad191dde8e25
5
5
  SHA512:
6
- metadata.gz: 56c35b423fb6b786a187548d9b9fe9a1d76f47da18dd6fb53eea1143593cbcfb6ff19de8f2ac5237193b6df7250726ef73d9e3c287655ded452331f99bca05f0
7
- data.tar.gz: cd58b3be796b1e185a697ac3f6dca2836154750bf856b4455e4dbd6c7224d6b629e3bd3184dd67ebd0195b0293affbb3feadfc62f9032fb07948f0b1bfafa2c0
6
+ metadata.gz: db4dd2ec06b1722637d716611c9d6ae6080f1b52ffa2da6129e8a421e0a034ea5923f56ea041869d69e7bd0fe48656a759f01c29d8067ec64cbd5e7ee7956c24
7
+ data.tar.gz: 56982a728fc581b06080ede29139b2245770affe03d9ce97633d18ac7d56341536740d4b15b52e1264ff26bc4b7e27ad4f7548489b0d0879f1c9569c34c1dd90
@@ -53,8 +53,6 @@ module Peeky
53
53
  # At times during debug or other edge cases, it may be useful to
54
54
  # pre-load this information early.
55
55
  def load
56
- ruby_instance_methods
57
- # ruby_instance_method_names
58
56
  signatures
59
57
  end
60
58
 
@@ -122,6 +120,12 @@ module Peeky
122
120
  @public_methods ||= signatures.select { |signature| signature.implementation_type == :method && signature.access_control == :public }
123
121
  end
124
122
 
123
+ # Get a list of class methods
124
+ # @return [Array<MethodInfo>] list of MethodInfo where type is :method
125
+ def class_methods
126
+ @class_methods ||= signatures.select { |signature| signature.implementation_type == :class_method }
127
+ end
128
+
125
129
  # Get a list methods ordered the way they are in the source code
126
130
  # @return [Array<MethodInfo>] list of MethodInfo
127
131
  def methods_source_order
@@ -180,9 +184,10 @@ module Peeky
180
184
  return @signatures if defined? @signatures
181
185
 
182
186
  @signatures = begin
183
- instance_methods = ruby_instance_methods.map { |im| MethodInfo.new(im, @instance) }
184
- private_methods = ruby_private_methods.map { |im| MethodInfo.new(im, @instance, access_control: :private) }
185
- instance_methods + private_methods
187
+ instance_methods = ruby_instance_methods.map { |im| MethodInfo.new(im, @instance) }
188
+ private_methods = ruby_private_methods.map { |im| MethodInfo.new(im, @instance, access_control: :private) }
189
+ class_methods = ruby_class_methods.map { |im| MethodInfo.new(im, @instance, implementation_type: :class_method) }
190
+ instance_methods + private_methods + class_methods
186
191
  end
187
192
  end
188
193
 
@@ -209,6 +214,10 @@ module Peeky
209
214
  "#{key.to_s.ljust(25)}: #{value}"
210
215
  end
211
216
 
217
+ def ruby_class_method_names
218
+ @ruby_class_method_names ||= instance.class.singleton_class.instance_methods(false).sort
219
+ end
220
+
212
221
  def ruby_instance_method_names
213
222
  @ruby_instance_method_names ||= instance.class.instance_methods(false).sort
214
223
  end
@@ -217,15 +226,24 @@ module Peeky
217
226
  @ruby_private_method_names ||= instance.private_methods(false).sort
218
227
  end
219
228
 
229
+ def ruby_class_methods
230
+ @ruby_class_methods ||= ruby_class_method_names.map { |method_name| instance.class.method(method_name) }
231
+ rescue StandardError => e
232
+ # puts 'ruby_class_methods'
233
+ puts e
234
+ end
235
+
220
236
  def ruby_private_methods
221
237
  @ruby_private_methods ||= ruby_private_method_names.map { |method_name| instance.method(method_name) }
222
238
  rescue StandardError => e
239
+ # puts 'ruby_private_methods'
223
240
  puts e
224
241
  end
225
242
 
226
243
  def ruby_instance_methods
227
244
  @ruby_instance_methods ||= ruby_instance_method_names.map { |method_name| instance.method(method_name) }
228
245
  rescue StandardError => e
246
+ # puts 'ruby_instance_methods'
229
247
  puts e
230
248
  end
231
249
  end
@@ -22,21 +22,21 @@ module Peeky
22
22
  #
23
23
 
24
24
  # Implementation type indicates the probable representation of this
25
- # method in ruby, was it `def method` or `attr_reader` / `attr_writer`
25
+ # method in ruby, was it
26
+ # instance method `def method`
27
+ # instance method reader `attr_reader`
28
+ # instance method writer `attr_writer`
29
+ # class method `def self.method`
26
30
  attr_reader :implementation_type
27
31
 
28
- def initialize(method, target_instance, access_control: :public)
32
+ def initialize(method, target_instance, implementation_type: :method, access_control: :public)
29
33
  @focal_method = method
30
34
  @target_instance = target_instance
31
35
  @access_control = access_control
36
+ @implementation_type = implementation_type
32
37
  @parameters = ParameterInfo.from_method(method)
33
- # stage 1
34
- # @implementation_type = :method
35
38
 
36
- # stage 2
37
39
  infer_implementation_type
38
-
39
- # stage 3
40
40
  infer_default_paramaters
41
41
  end
42
42
 
@@ -55,20 +55,13 @@ module Peeky
55
55
  end
56
56
  end
57
57
 
58
- # Infer implementation type [:method, :attr_reader or :attr_writer]
59
- # rubocop:disable Lint/DuplicateBranch
58
+ # Infer implementation type [:class_method, :method, :attr_reader or :attr_writer]
60
59
  def infer_implementation_type
61
- @implementation_type = if @target_instance.nil?
62
- :method
63
- elsif match(Peeky::Predicates::AttrReaderPredicate)
64
- :attr_reader
65
- elsif match(Peeky::Predicates::AttrWriterPredicate)
66
- :attr_writer
67
- else
68
- :method
69
- end
60
+ return unless @implementation_type == :method
61
+
62
+ @implementation_type = :attr_reader if match(Peeky::Predicates::AttrReaderPredicate)
63
+ @implementation_type = :attr_writer if match(Peeky::Predicates::AttrWriterPredicate)
70
64
  end
71
- # rubocop:enable Lint/DuplicateBranch
72
65
 
73
66
  # Get parameter by name
74
67
  #
@@ -101,7 +94,13 @@ module Peeky
101
94
  return unless optional?
102
95
 
103
96
  tracer.enable do
104
- @target_instance.instance_eval(minimalist_method)
97
+ if @implementation_type == :method
98
+ @target_instance.instance_eval(minimalist_method)
99
+ end
100
+ if @implementation_type == :class_method
101
+ minimalist_method = "#{@target_instance.class.name}.#{minimalist_method}"
102
+ @target_instance.class.instance_eval(minimalist_method)
103
+ end
105
104
  rescue StandardError => e
106
105
  # just print the error for now, we are only attempting to capture the
107
106
  # first call, any errors inside the call cannot be dealt with and should
data/lib/peeky/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Peeky
4
- VERSION = '0.0.42'
4
+ VERSION = '0.0.43'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: peeky
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.42
4
+ version: 0.0.43
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cruwys