peeky 0.0.43 → 0.0.45

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a5ace1c867116904f98e261077b746cd8d2621f657a391e79c80f3f57edf4583
4
- data.tar.gz: 195ab81abb7ab1198c19613c4fe2f4e730fd2b6a6c2654938396ad191dde8e25
3
+ metadata.gz: b59687793d9f01e4a7c6f0db2e1fdd8e20b614446815c82f13decabf5661704b
4
+ data.tar.gz: d49b1a2a72414094caff610f371fa242688e78b07f91edb38d7565a9aa5f650c
5
5
  SHA512:
6
- metadata.gz: db4dd2ec06b1722637d716611c9d6ae6080f1b52ffa2da6129e8a421e0a034ea5923f56ea041869d69e7bd0fe48656a759f01c29d8067ec64cbd5e7ee7956c24
7
- data.tar.gz: 56982a728fc581b06080ede29139b2245770affe03d9ce97633d18ac7d56341536740d4b15b52e1264ff26bc4b7e27ad4f7548489b0d0879f1c9569c34c1dd90
6
+ metadata.gz: 15d8633c3f3e3e917161c4b6acaa40e16cf3a6c58fb4cbeb2c4bfb00c8f3f168e81092aa8ecd397fedcba521a4b9a58a4101e9fa70598b20e1c623f4f27c3636
7
+ data.tar.gz: cf82156956b67d6b90f467ce816418cd9a56fcc05e0f98bd5c96e29fe448fde7727420489114651fdaab89c27a004759bf8508d79c4f15fafdfbebe1e59b3421
data/Guardfile CHANGED
@@ -23,7 +23,7 @@ group :green_pass_then_cop, halt_on_fail: true do
23
23
  watch(%r{^lib/peeky/commands/(.+)\.rb$}) { |m| "spec/unit/commands/#{m[1]}_spec.rb" }
24
24
  end
25
25
 
26
- guard :rubocop, all_on_start: false, cli: ['--format', 'clang'] do
26
+ guard :rubocop, all_on_start: false, cli: ['--format', 'clang', '-a'] do
27
27
  watch(%r{.+\.rb$})
28
28
  watch(%r{(?:.+/)?\.rubocop(?:_todo)?\.yml$}) { |m| File.dirname(m[0]) }
29
29
  end
@@ -33,13 +33,16 @@ module Peeky
33
33
  result.push kv('# of methods', all_methods.length)
34
34
  result.push kv('# of methods - public', public_methods.length)
35
35
  result.push kv('# of methods - private', private_methods.length)
36
+ result.push kv('# of class methods', class_methods.length)
37
+
36
38
  else
37
- result.push kv('# of accessors', '')
38
- result.push kv('# of readers', '')
39
- result.push kv('# of writers', '')
40
- result.push kv('# of methods', '')
41
- result.push kv('# of methods - public', '')
42
- result.push kv('# of methods - private', '')
39
+ result.push 'Not Loaded'
40
+ # result.push kv('# of accessors', '')
41
+ # result.push kv('# of readers', '')
42
+ # result.push kv('# of writers', '')
43
+ # result.push kv('# of methods', '')
44
+ # result.push kv('# of methods - public', '')
45
+ # result.push kv('# of methods - private', '')
43
46
  end
44
47
  result.join("\n")
45
48
  end
@@ -88,19 +88,16 @@ module Peeky
88
88
  # The tests are now down to 5 seconds, but it highlights the cost of use
89
89
  # TracePoint.
90
90
  def infer_default_paramaters
91
- minimalist_method = Peeky::Renderer::MethodCallMinimumParamsRender.new(self).render
91
+ class_name = @implementation_type == :class_method ? @target_instance.class.name : nil
92
+ minimalist_method = Peeky::Renderer::MethodCallMinimumParamsRender.new(self, class_name: class_name).render
92
93
 
93
94
  return if minimalist_method.end_with?('=')
94
95
  return unless optional?
95
96
 
96
97
  tracer.enable do
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
98
+ # TODO: minimalist method should be able to handle class methods
99
+ @target_instance.instance_eval(minimalist_method) if @implementation_type == :method
100
+ @target_instance.class.instance_eval(minimalist_method) if @implementation_type == :class_method
104
101
  rescue StandardError => e
105
102
  # just print the error for now, we are only attempting to capture the
106
103
  # first call, any errors inside the call cannot be dealt with and should
@@ -24,21 +24,9 @@ module Peeky
24
24
  output.push('')
25
25
  end
26
26
 
27
- methods = render_methods(@class_info.public_methods)
28
-
29
- if methods.length.positive?
30
- output.push("-- Public Methods #{'-' * 82}")
31
- output.push(*methods)
32
- output.push('')
33
- end
34
-
35
- methods = render_methods(@class_info.private_methods)
36
-
37
- if methods.length.positive?
38
- output.push("-- Private Methods #{'-' * 82}")
39
- output.push(*methods)
40
- output.push('')
41
- end
27
+ render_methods_with_heading(output, @class_info.public_methods, 'Public Methods')
28
+ render_methods_with_heading(output, @class_info.class_methods, 'Class Methods')
29
+ render_methods_with_heading(output, @class_info.private_methods, 'Private Methods')
42
30
 
43
31
  output.pop if output.last == ''
44
32
 
@@ -78,6 +66,16 @@ module Peeky
78
66
  @class_info.writers.map { |attr| kv('attr_writer', attr.name) }
79
67
  end
80
68
 
69
+ def render_methods_with_heading(output, method_list, heading)
70
+ methods = render_methods(method_list)
71
+
72
+ return unless methods.length.positive?
73
+
74
+ output.push("-- #{heading} #{'-' * 82}")
75
+ output.push(*methods)
76
+ output.push('')
77
+ end
78
+
81
79
  def render_methods(method_list)
82
80
  method_list.flat_map do |method|
83
81
  [
@@ -2,32 +2,44 @@
2
2
 
3
3
  module Peeky
4
4
  module Renderer
5
- # Render: Class Interface
5
+ # Render: Class Interface Example
6
6
  #
7
- # Example output:
8
- # class SampleClassClassInterfaceRender
9
- # attr_accessor :a
7
+ # class ComplexClass
8
+ # attr_accessor :a_read_write1
9
+ # attr_accessor :a_read_write2
10
+
11
+ # attr_reader :b_another_reader
12
+ # attr_reader :b_reader
13
+ # attr_reader :looks_like_an_attr_reader
14
+
15
+ # attr_writer :c_another_writer
16
+ # attr_writer :c_writer
17
+
18
+ # def alpha_sort1; end
19
+ # def alpha_sort2; end
20
+ # def destructive!; end
21
+ # def do_something_method; end
22
+ # def method_01(aaa); end
23
+ # def method_02(aaa, bbb = 1); end
24
+ # def method_03(aaa, bbb = 1, ccc = 2); end
25
+ # def method_04(*aaa); end
26
+ # def method_05(aaa, bbb = 1, *ccc); end
27
+ # def method_06(**aaa); end
28
+ # def method_07(aaa, *bbb, ccc: 'string1', **ddd); end
29
+ # def method_08(aaa, *bbb, **ccc, &ddd); end
30
+ # def method_09(aaa:); end
31
+ # def method_10(aaa:, bbb: 1); end
32
+ # def method_with_every_type_of_paramater(aaa, bbb = 1, *ccc, ddd:, eee: 1, **fff, &ggg);end
33
+ # def questionable?; end
10
34
  #
11
- # attr_reader :b
35
+ # class << self
36
+ # def klass_complex(aaa, bbb = nil, *ccc, ddd:, eee: , **fff, &ggg); end
37
+ # def klass_simple(first_param); end
38
+ # end
12
39
  #
13
- # attr_writer :c
40
+ # private
14
41
  #
15
- # def alpha_sort1; end
16
- # def alpha_sort2; end
17
- # def d; end
18
- # def e(aaa); end
19
- # def f(aaa, bbb = nil); end
20
- # def g(aaa, bbb = nil, ccc = nil); end
21
- # def h(*aaa); end
22
- # def i(aaa, bbb, *ccc); end
23
- # def j(**aaa); end
24
- # def k(aaa, *bbb, **ccc); end
25
- # def l(aaa, *bbb, **ccc, &ddd); end
26
- # def m(aaa:); end
27
- # def n(aaa:, bbb: nil); end
28
- # def p?; end
29
- # def q!; end
30
- # def z(aaa, bbb = nil, *ccc, ddd:, eee: nil, **fff, &ggg); end
42
+ # def keep_me_private; end
31
43
  # end
32
44
  class ClassInterfaceRender
33
45
  # ClassInfo with information about the class instance to be rendered.
@@ -38,28 +50,27 @@ module Peeky
38
50
  end
39
51
 
40
52
  # Render the class interface
41
- # rubocop:disable Metrics/AbcSize
42
53
  def render
43
54
  @indent = ''
44
- output = []
45
- output.push render_start
55
+ @output = []
56
+ @output.push render_start
46
57
  @indent = ' '
47
- output += render_accessors
48
- output += render_readers
49
- output += render_writers
50
- output += render_methods(@class_info.public_methods)
51
- unless @class_info.private_methods.length.zero?
52
- output += ["#{@indent}private", '']
53
- output += render_methods(@class_info.private_methods)
54
- end
55
- output.pop if output.last == ''
58
+
59
+ render_accessors
60
+ render_readers
61
+ render_writers
62
+
63
+ render_methods(@class_info.public_methods)
64
+ render_class_methods(@class_info.class_methods)
65
+ render_private_methods(@class_info.private_methods)
66
+
67
+ @output.pop if @output.last == ''
56
68
 
57
69
  @indent = ''
58
- output.push render_end
70
+ @output.push render_end
59
71
 
60
- output.join("\n")
72
+ @output.join("\n")
61
73
  end
62
- # rubocop:enable Metrics/AbcSize
63
74
 
64
75
  private
65
76
 
@@ -70,19 +81,19 @@ module Peeky
70
81
  def render_accessors
71
82
  result = @class_info.accessors.map { |attr| "#{@indent}attr_accessor :#{attr.name}" }
72
83
  result.push '' unless result.length.zero?
73
- result
84
+ @output += result
74
85
  end
75
86
 
76
87
  def render_readers
77
88
  result = @class_info.readers.map { |attr| "#{@indent}attr_reader :#{attr.name}" }
78
89
  result.push '' unless result.length.zero?
79
- result
90
+ @output += result
80
91
  end
81
92
 
82
93
  def render_writers
83
94
  result = @class_info.writers.map { |attr| "#{@indent}attr_writer :#{attr.name}" }
84
95
  result.push '' unless result.length.zero?
85
- result
96
+ @output += result
86
97
  end
87
98
 
88
99
  def render_methods(method_list)
@@ -91,7 +102,25 @@ module Peeky
91
102
  "#{@indent}#{render_signature.render}"
92
103
  end
93
104
  result.push '' unless result.length.zero?
94
- result
105
+ @output += result
106
+ end
107
+
108
+ def render_class_methods(methods)
109
+ return if methods.length.zero?
110
+
111
+ @output += ["#{@indent}class << self"]
112
+ @indent += ' '
113
+ @output += render_methods(methods)
114
+ @indent.delete_suffix!(' ')
115
+ @output.pop if @output.last == ''
116
+ @output += ["#{@indent}end", '']
117
+ end
118
+
119
+ def render_private_methods(methods)
120
+ return if methods.length.zero?
121
+
122
+ @output += ["#{@indent}private", '']
123
+ @output += render_methods(methods)
95
124
  end
96
125
 
97
126
  def render_end
@@ -33,26 +33,33 @@ module Peeky
33
33
 
34
34
  # Render the class interface with YARD documentation
35
35
  def render
36
- output = []
37
- output.push render_start
36
+ @output = []
37
+
38
+ render_start
38
39
  @indent += ' '
39
- output += (render_accessors + render_readers + render_writers + render_methods)
40
- output.pop if output.last == ''
40
+
41
+ render_accessors
42
+ render_readers
43
+ render_writers
44
+
45
+ render_public_methods
46
+ render_class_methods
47
+ render_private_methods
48
+
49
+ @output.pop if @output.last == ''
41
50
 
42
51
  @indent = @indent[0..-3]
43
52
 
44
- output.push render_end
53
+ @output.push render_end
45
54
 
46
- output.join("\n")
55
+ @output.join("\n")
47
56
  end
48
57
 
49
58
  private
50
59
 
51
60
  def render_start
52
- [
53
- "#{@indent}# #{@class_info.class_name.titleize.humanize}",
54
- "#{@indent}class #{@class_info.class_name}"
55
- ]
61
+ @output.push "#{@indent}# #{@class_info.class_name.titleize.humanize}"
62
+ @output.push "#{@indent}class #{@class_info.class_name}"
56
63
  end
57
64
 
58
65
  def render_accessors
@@ -63,7 +70,7 @@ module Peeky
63
70
  result.push "#{@indent}attr_accessor :#{attr.name}"
64
71
  end
65
72
  result.push '' unless result.length.zero?
66
- result
73
+ @output += result
67
74
  end
68
75
 
69
76
  def render_readers
@@ -74,7 +81,7 @@ module Peeky
74
81
  result.push "#{@indent}attr_reader :#{attr.name}"
75
82
  end
76
83
  result.push '' unless result.length.zero?
77
- result
84
+ @output += result
78
85
  end
79
86
 
80
87
  def render_writers
@@ -85,23 +92,40 @@ module Peeky
85
92
  result.push "#{@indent}attr_writer :#{attr.name}"
86
93
  end
87
94
  result.push '' unless result.length.zero?
88
- result
95
+ @output += result
89
96
  end
90
97
 
91
- # rubocop:disable Metics/AbcSize
92
- def render_methods
98
+ def render_public_methods
93
99
  result = []
94
100
  class_info.public_methods.map.with_index do |method_signature, index|
95
101
  render_method(result, method_signature, index)
96
102
  end
103
+ result.push '' unless result.length.zero?
104
+ @output += result
105
+ end
106
+
107
+ def render_class_methods
108
+ return if class_info.class_methods.length.zero?
109
+
110
+ result = ["#{@indent}# Class methods", "#{@indent}class << self"]
111
+ @indent += ' '
112
+ class_info.class_methods.map.with_index do |method_signature, index|
113
+ render_method(result, method_signature, index)
114
+ end
115
+ @indent.delete_suffix!(' ')
116
+ result.push "#{@indent}end"
117
+
118
+ @output += result
119
+ end
120
+
121
+ def render_private_methods
122
+ result = []
97
123
  class_info.private_methods.map.with_index do |method_signature, index|
98
124
  result.push "\n#{indent}private\n" if index.zero?
99
125
  render_method(result, method_signature, index)
100
126
  end
101
- result.push '' unless result.length.zero?
102
- result
127
+ @output += result
103
128
  end
104
- # rubocop:enable Metics/AbcSize
105
129
 
106
130
  # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
107
131
  def render_method(result, method_signature, index)
@@ -13,7 +13,8 @@ module Peeky
13
13
 
14
14
  def initialize(method_signature, **opts)
15
15
  # instance_name = opts[:instance_name] || 'instance'
16
- @instance_name = opts[:instance_name]
16
+ @instance_name = opts[:instance_name]
17
+ @class_name = opts[:class_name]
17
18
  @method_signature = method_signature
18
19
  end
19
20
 
@@ -29,11 +30,10 @@ module Peeky
29
30
 
30
31
  params = minimal_call_parameters.length.zero? ? '' : "(#{minimal_call_parameters})"
31
32
 
32
- if @instance_name.nil?
33
- "#{name}#{params}"
34
- else
35
- "#{@instance_name}.#{name}#{params}"
36
- end
33
+ return "#{@instance_name}.#{name}#{params}" unless @instance_name.nil?
34
+ return "#{@class_name}.#{name}#{params}" unless @class_name.nil?
35
+
36
+ "#{name}#{params}"
37
37
  end
38
38
  end
39
39
  end
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.43'
4
+ VERSION = '0.0.45'
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.43
4
+ version: 0.0.45
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cruwys