peeky 0.0.28 → 0.0.31
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/README.md +69 -4
- data/STORIES.md +11 -15
- data/USAGE.md +322 -0
- data/lib/peeky/api.rb +4 -2
- data/lib/peeky/class_info.rb +17 -11
- data/lib/peeky/example/yard_sample.rb +1 -0
- data/lib/peeky/parameter_info.rb +96 -21
- data/lib/peeky/renderer/class_interface_yard_render.rb +4 -1
- data/lib/peeky/version.rb +1 -1
- data/peeky.gemspec +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: edb80ec928d5d4495d464467e28bbb6b16638a14773eca16891ddbea915335a5
|
4
|
+
data.tar.gz: febac36ff7fa54d618d0ef6f3ef20da522b5918904c76550b823f11e1eb6ffde
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c984b3df997d970c6da34e654495802f54ce67c18bf7a057e22b56ab6f0c7b9e68579834715b09288059ac389662d5c3504ebe1aa42eee7675978b8010cb1b3
|
7
|
+
data.tar.gz: c2e45fbfda42652aeec5334edc8a5d596948eba45ecaa91d3a3f8522e603c39284deff97a78abc519edc0be675e29811624b7c51a2e17d48a3fe501acd9ca669
|
data/README.md
CHANGED
@@ -30,17 +30,82 @@ gem install peeky
|
|
30
30
|
|
31
31
|
As a Ruby Developer, I should be able to Reverse engineer classes and methods, so that I can document and understand them
|
32
32
|
|
33
|
-
See all [stories](./
|
33
|
+
See all [stories](./STORIES.md)
|
34
34
|
|
35
35
|
### Featured Stories
|
36
36
|
|
37
37
|
- As a Developer, I should be able to interrogate class instance information, so that I can reverse engineer a ruby class
|
38
|
-
- As a Developer, I can render method with minimal parameter calls, So that I know the minimum parameters when calling a method
|
38
|
+
- As a Developer, I can render a method with minimal parameter calls, So that I know the minimum parameters when calling a method
|
39
39
|
- As a Developer, I can render a class with instance attributes and methods, So that I can quickly mock out an entire class
|
40
40
|
|
41
41
|
## Usage
|
42
42
|
|
43
|
-
|
43
|
+
See all [usages](./USAGE.md)
|
44
|
+
|
45
|
+
### Basic Example
|
46
|
+
|
47
|
+
This example assumes you have this simple class
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
module Sample
|
53
|
+
class SimpleClass
|
54
|
+
attr_accessor :read_write
|
55
|
+
|
56
|
+
def position_and_optional(aaa, bbb = 1)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
```
|
61
|
+
|
62
|
+
|
63
|
+
### Rendering Examples
|
64
|
+
|
65
|
+
Here a list of example renderers for the simple class
|
66
|
+
|
67
|
+
#### Class interface
|
68
|
+
Render simple class using class_interface renderer with compact formatting
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
puts api.render_class(:class_interface, instance: Sample::SimpleClass.new)
|
72
|
+
```
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
class SimpleClass
|
78
|
+
attr_accessor :read_write
|
79
|
+
|
80
|
+
def position_and_optional(aaa, bbb = nil); end
|
81
|
+
end
|
82
|
+
```
|
83
|
+
|
84
|
+
#### Documented class interface
|
85
|
+
Render simple class using class_interface_yard renderer to product YARD compatible documentation
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
puts api.render_class(:class_interface_yard, instance: Sample::SimpleClass.new)
|
89
|
+
```
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
class SimpleClass
|
95
|
+
# Read write
|
96
|
+
attr_accessor :read_write
|
97
|
+
|
98
|
+
# Position and optional
|
99
|
+
#
|
100
|
+
# @param aaa [String] aaa (required)
|
101
|
+
# @param bbb [String] bbb (optional)
|
102
|
+
def position_and_optional(aaa, bbb = nil)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
```
|
106
|
+
|
107
|
+
|
108
|
+
|
44
109
|
|
45
110
|
## Development
|
46
111
|
|
@@ -58,7 +123,7 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
58
123
|
|
59
124
|
## Code of Conduct
|
60
125
|
|
61
|
-
Everyone interacting in the Peeky project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the.
|
126
|
+
Everyone interacting in the Peeky project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/peeky/blob/master/CODE_OF_CONDUCT.md).
|
62
127
|
|
63
128
|
## Copyright
|
64
129
|
|
data/STORIES.md
CHANGED
@@ -4,17 +4,12 @@
|
|
4
4
|
|
5
5
|
As a Ruby Developer, I should be able to Reverse engineer classes and methods, so that I can document and understand them
|
6
6
|
|
7
|
-
## Development
|
7
|
+
## Development radar
|
8
8
|
|
9
9
|
|
10
10
|
### Tasks next on list
|
11
11
|
|
12
|
-
As a Developer, I can
|
13
|
-
|
14
|
-
- Add simplified API with examples
|
15
|
-
- Start documenting usage instructions
|
16
|
-
|
17
|
-
As a Developer, I can use Peeky with a simple API, so that I use this GEM quickly
|
12
|
+
As a Developer, I can use Peeky with a simple API, so that I use Peeky quickly
|
18
13
|
|
19
14
|
- Add simplified API with examples
|
20
15
|
- Start documenting usage instructions
|
@@ -30,12 +25,6 @@ As a Developer, I can quickly build requirements, so that I can document project
|
|
30
25
|
|
31
26
|
### Stories - completed
|
32
27
|
|
33
|
-
As a David, I can edify Karin, because she is cool
|
34
|
-
|
35
|
-
- karin_is_awesome
|
36
|
-
- i_am_very_grateful_for_karin
|
37
|
-
- karin_the_beautiful
|
38
|
-
|
39
28
|
As a Developer, I can render a class with instance attributes and methods, So that I can quickly mock out an entire class
|
40
29
|
|
41
30
|
- Render: Class Interface
|
@@ -48,7 +37,7 @@ As a Developer, I can see the method signature of a method, So that I understand
|
|
48
37
|
|
49
38
|
- Render: Method Signature in compact format
|
50
39
|
|
51
|
-
As a Developer, I can render method with minimal parameter calls, So that I know the minimum parameters when calling a method
|
40
|
+
As a Developer, I can render a method with minimal parameter calls, So that I know the minimum parameters when calling a method
|
52
41
|
|
53
42
|
- Render: Simple instance method calls with minimum parameters
|
54
43
|
|
@@ -65,7 +54,14 @@ As a Developer, I should be able to interrogate class instance information, so t
|
|
65
54
|
- ClassInfo stores information about a ruby class. Only support instance methods
|
66
55
|
|
67
56
|
|
68
|
-
|
57
|
+
### Tasks - completed
|
58
|
+
|
59
|
+
As a Developer, I can render a class with RDoc documentation, so that I do not have to manually type RDoc references
|
60
|
+
|
61
|
+
|
62
|
+
As a Developer, I can read detailed API documentation on Peaky, so that I use Peeky quickly
|
63
|
+
|
64
|
+
- Acid Test: Use the YARD renderer to document Peaky the GEM
|
69
65
|
|
70
66
|
Setup GitHub Action (test and lint)
|
71
67
|
|
data/USAGE.md
ADDED
@@ -0,0 +1,322 @@
|
|
1
|
+
# Peeky
|
2
|
+
|
3
|
+
> Peeky is a Ruby GEM for peaking into ruby classes and extracting meta
|
4
|
+
|
5
|
+
As a Ruby Developer, I should be able to Reverse engineer classes and methods, so that I can document and understand them
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
### Sample Classes
|
10
|
+
|
11
|
+
The usage examples listed below will work with these sample classes
|
12
|
+
|
13
|
+
#### Simple example
|
14
|
+
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
module Sample
|
18
|
+
class SimpleClass
|
19
|
+
attr_accessor :read_write
|
20
|
+
|
21
|
+
def position_and_optional(aaa, bbb = 1)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
#### Complex example
|
28
|
+
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
module Sample
|
32
|
+
class ComplexClass
|
33
|
+
attr_accessor :a_read_write1, :a_read_write2
|
34
|
+
attr_reader :b_reader, :b_another_reader
|
35
|
+
attr_writer :c_writer, :c_another_writer
|
36
|
+
|
37
|
+
def do_something_method
|
38
|
+
end
|
39
|
+
|
40
|
+
def looks_like_an_attr_reader
|
41
|
+
@looks_like_an_attr_reader ||= 5
|
42
|
+
end
|
43
|
+
|
44
|
+
def method_01(aaa); end
|
45
|
+
|
46
|
+
def method_02(aaa, bbb = 1); end
|
47
|
+
|
48
|
+
def method_03(aaa, bbb = 1, ccc = 2); end
|
49
|
+
|
50
|
+
def method_04(*aaa); end
|
51
|
+
|
52
|
+
def method_05(aaa, bbb = 1, *ccc); end
|
53
|
+
|
54
|
+
def method_06(**aaa); end
|
55
|
+
|
56
|
+
def method_07(aaa, *bbb, **ccc); end
|
57
|
+
|
58
|
+
def method_08(aaa, *bbb, **ccc, &ddd); end
|
59
|
+
|
60
|
+
def method_09(aaa:); end
|
61
|
+
|
62
|
+
def method_10(aaa:, bbb: 1); end
|
63
|
+
|
64
|
+
def questionable?; end
|
65
|
+
|
66
|
+
def destructive!; end
|
67
|
+
|
68
|
+
def method_with_every_type_of_paramater(aaa, bbb = 1, *ccc, ddd:, eee: 1, **fff, &ggg); end
|
69
|
+
|
70
|
+
# Check that methods are sorted
|
71
|
+
def alpha_sort2; end
|
72
|
+
def alpha_sort1; end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
```
|
76
|
+
|
77
|
+
|
78
|
+
### Build Class Information
|
79
|
+
|
80
|
+
Use build_class_info to extract meta data from a ruby class
|
81
|
+
|
82
|
+
#### Build ClassInfo
|
83
|
+
By default information is lazy loaded only when accessed
|
84
|
+
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
class_info = api.build_class_info(Sample::SimpleClass.new)
|
88
|
+
|
89
|
+
puts class_info
|
90
|
+
```
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
```shell
|
95
|
+
Sample::SimpleClass
|
96
|
+
```
|
97
|
+
|
98
|
+
#### Build ClassInfo - pre-loaded
|
99
|
+
Pre-load will ensure that methods and parameters are loaded straight away.
|
100
|
+
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
class_info = api.build_class_info(Sample::ComplexClass.new, lazy: false)
|
104
|
+
|
105
|
+
puts class_info
|
106
|
+
```
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
```shell
|
111
|
+
Sample::ComplexClass
|
112
|
+
```
|
113
|
+
|
114
|
+
|
115
|
+
### Render Class
|
116
|
+
|
117
|
+
Render a class using a pre-defined class renderer that can be referenced by key
|
118
|
+
|
119
|
+
#### Render class interface using class_info
|
120
|
+
Render a basic class interface in compact format "One line per method".
|
121
|
+
|
122
|
+
Note: Modules are not yet supported in Peeky
|
123
|
+
|
124
|
+
|
125
|
+
```ruby
|
126
|
+
class_info = api.build_class_info(Sample::SimpleClass.new)
|
127
|
+
|
128
|
+
puts api.render_class(:class_interface, class_info: class_info)
|
129
|
+
```
|
130
|
+
|
131
|
+
#### Render class interface using an instance of the intended class
|
132
|
+
|
133
|
+
|
134
|
+
```ruby
|
135
|
+
puts api.render_class(:class_interface, instance: Sample::SimpleClass.new)
|
136
|
+
```
|
137
|
+
|
138
|
+
|
139
|
+
### Render Class Examples
|
140
|
+
|
141
|
+
Here a list of example renderers for the complex class
|
142
|
+
|
143
|
+
#### Class interface
|
144
|
+
Render simple class using class_interface renderer
|
145
|
+
|
146
|
+
```ruby
|
147
|
+
puts api.render_class(:class_interface, instance: Sample::SimpleClass.new)
|
148
|
+
```
|
149
|
+
|
150
|
+
|
151
|
+
|
152
|
+
```ruby
|
153
|
+
class ComplexClass
|
154
|
+
attr_accessor :a_read_write1
|
155
|
+
attr_accessor :a_read_write2
|
156
|
+
|
157
|
+
attr_reader :b_another_reader
|
158
|
+
attr_reader :b_reader
|
159
|
+
attr_reader :looks_like_an_attr_reader
|
160
|
+
|
161
|
+
attr_writer :c_another_writer
|
162
|
+
attr_writer :c_writer
|
163
|
+
|
164
|
+
def alpha_sort1; end
|
165
|
+
def alpha_sort2; end
|
166
|
+
def destructive!; end
|
167
|
+
def do_something_method; end
|
168
|
+
def method_01(aaa); end
|
169
|
+
def method_02(aaa, bbb = nil); end
|
170
|
+
def method_03(aaa, bbb = nil, ccc = nil); end
|
171
|
+
def method_04(*aaa); end
|
172
|
+
def method_05(aaa, bbb = nil, *ccc); end
|
173
|
+
def method_06(**aaa); end
|
174
|
+
def method_07(aaa, *bbb, **ccc); end
|
175
|
+
def method_08(aaa, *bbb, **ccc, &ddd); end
|
176
|
+
def method_09(aaa:); end
|
177
|
+
def method_10(aaa:, bbb: nil); end
|
178
|
+
def method_with_every_type_of_paramater(aaa, bbb = nil, *ccc, ddd:, eee: nil, **fff, &ggg);end
|
179
|
+
def questionable?; end
|
180
|
+
end
|
181
|
+
```
|
182
|
+
|
183
|
+
#### Class interface - YARD
|
184
|
+
Render complex class using class_interface_yard renderer
|
185
|
+
|
186
|
+
```ruby
|
187
|
+
puts api.render_class(:class_interface_yard, instance: Sample::ComplexClass.new)
|
188
|
+
```
|
189
|
+
|
190
|
+
|
191
|
+
|
192
|
+
```ruby
|
193
|
+
class ComplexClass
|
194
|
+
# A read write1
|
195
|
+
attr_accessor :a_read_write1
|
196
|
+
|
197
|
+
# A read write2
|
198
|
+
attr_accessor :a_read_write2
|
199
|
+
|
200
|
+
# B another reader
|
201
|
+
attr_reader :b_another_reader
|
202
|
+
|
203
|
+
# B reader
|
204
|
+
attr_reader :b_reader
|
205
|
+
|
206
|
+
# Looks like an attr reader
|
207
|
+
attr_reader :looks_like_an_attr_reader
|
208
|
+
|
209
|
+
# C another writer
|
210
|
+
attr_writer :c_another_writer
|
211
|
+
|
212
|
+
# C writer
|
213
|
+
attr_writer :c_writer
|
214
|
+
|
215
|
+
# Alpha sort1
|
216
|
+
def alpha_sort1
|
217
|
+
end
|
218
|
+
|
219
|
+
# Alpha sort2
|
220
|
+
def alpha_sort2
|
221
|
+
end
|
222
|
+
|
223
|
+
# Destructive!
|
224
|
+
def destructive!
|
225
|
+
end
|
226
|
+
|
227
|
+
# Do something method
|
228
|
+
def do_something_method
|
229
|
+
end
|
230
|
+
|
231
|
+
# Method 01
|
232
|
+
#
|
233
|
+
# @param aaa [String] aaa (required)
|
234
|
+
def method_01(aaa)
|
235
|
+
end
|
236
|
+
|
237
|
+
# Method 02
|
238
|
+
#
|
239
|
+
# @param aaa [String] aaa (required)
|
240
|
+
# @param bbb [String] bbb (optional)
|
241
|
+
def method_02(aaa, bbb = nil)
|
242
|
+
end
|
243
|
+
|
244
|
+
# Method 03
|
245
|
+
#
|
246
|
+
# @param aaa [String] aaa (required)
|
247
|
+
# @param bbb [String] bbb (optional)
|
248
|
+
# @param ccc [String] ccc (optional)
|
249
|
+
def method_03(aaa, bbb = nil, ccc = nil)
|
250
|
+
end
|
251
|
+
|
252
|
+
# Method 04
|
253
|
+
#
|
254
|
+
# @param aaa [Array<Object>] *aaa - list of aaa
|
255
|
+
def method_04(*aaa)
|
256
|
+
end
|
257
|
+
|
258
|
+
# Method 05
|
259
|
+
#
|
260
|
+
# @param aaa [String] aaa (required)
|
261
|
+
# @param bbb [String] bbb (optional)
|
262
|
+
# @param ccc [Array<Object>] *ccc - list of ccc
|
263
|
+
def method_05(aaa, bbb = nil, *ccc)
|
264
|
+
end
|
265
|
+
|
266
|
+
# Method 06
|
267
|
+
#
|
268
|
+
# @param aaa [<key: value>...] **aaa - list of key/values
|
269
|
+
def method_06(**aaa)
|
270
|
+
end
|
271
|
+
|
272
|
+
# Method 07
|
273
|
+
#
|
274
|
+
# @param aaa [String] aaa (required)
|
275
|
+
# @param bbb [Array<Object>] *bbb - list of bbb
|
276
|
+
# @param ccc [<key: value>...] **ccc - list of key/values
|
277
|
+
def method_07(aaa, *bbb, **ccc)
|
278
|
+
end
|
279
|
+
|
280
|
+
# Method 08
|
281
|
+
#
|
282
|
+
# @param aaa [String] aaa (required)
|
283
|
+
# @param bbb [Array<Object>] *bbb - list of bbb
|
284
|
+
# @param ccc [<key: value>...] **ccc - list of key/values
|
285
|
+
# @param ddd [Block] &ddd
|
286
|
+
def method_08(aaa, *bbb, **ccc, &ddd)
|
287
|
+
end
|
288
|
+
|
289
|
+
# Method 09
|
290
|
+
#
|
291
|
+
# @param aaa [String] aaa: <value for aaa> (required)
|
292
|
+
def method_09(aaa:)
|
293
|
+
end
|
294
|
+
|
295
|
+
# Method 10
|
296
|
+
#
|
297
|
+
# @param aaa [String] aaa: <value for aaa> (required)
|
298
|
+
# @param bbb [String] bbb: <value for bbb> (optional)
|
299
|
+
def method_10(aaa:, bbb: nil)
|
300
|
+
end
|
301
|
+
|
302
|
+
# Method with every type of paramater
|
303
|
+
#
|
304
|
+
# @param aaa [String] aaa (required)
|
305
|
+
# @param bbb [String] bbb (optional)
|
306
|
+
# @param ccc [Array<Object>] *ccc - list of ccc
|
307
|
+
# @param ddd [String] ddd: <value for ddd> (required)
|
308
|
+
# @param eee [String] eee: <value for eee> (optional)
|
309
|
+
# @param fff [<key: value>...] **fff - list of key/values
|
310
|
+
# @param ggg [Block] &ggg
|
311
|
+
def method_with_every_type_of_paramater(aaa, bbb = nil, *ccc, ddd:, eee: nil, **fff, &ggg)
|
312
|
+
end
|
313
|
+
|
314
|
+
# Questionable?
|
315
|
+
#
|
316
|
+
# @return [Boolean] true when questionable?
|
317
|
+
def questionable?
|
318
|
+
end
|
319
|
+
end
|
320
|
+
```
|
321
|
+
|
322
|
+
#### Debug class info
|
data/lib/peeky/api.rb
CHANGED
@@ -16,8 +16,10 @@ module Peeky
|
|
16
16
|
# ClassInfo stores information about the instance of a
|
17
17
|
# class that is passed in including methods, attr_accessors
|
18
18
|
# attr_readers and attr_writers.
|
19
|
-
def build_class_info(instance)
|
20
|
-
Peeky::ClassInfo.new(instance)
|
19
|
+
def build_class_info(instance, lazy: true)
|
20
|
+
ci = Peeky::ClassInfo.new(instance)
|
21
|
+
ci.load unless lazy
|
22
|
+
ci
|
21
23
|
end
|
22
24
|
|
23
25
|
# Render a class using a predefined class renderer
|
data/lib/peeky/class_info.rb
CHANGED
@@ -17,6 +17,23 @@ module Peeky
|
|
17
17
|
@instance = instance
|
18
18
|
end
|
19
19
|
|
20
|
+
def to_s
|
21
|
+
class_full_name
|
22
|
+
end
|
23
|
+
|
24
|
+
# Load class_info
|
25
|
+
#
|
26
|
+
# Accessing information about methods and parameters is currently
|
27
|
+
# lazy-loaded via memoization.
|
28
|
+
#
|
29
|
+
# At times during debug or other edge cases, it may be useful to
|
30
|
+
# pre-load this information early.
|
31
|
+
def load
|
32
|
+
ruby_instance_methods
|
33
|
+
ruby_instance_method_names
|
34
|
+
signatures
|
35
|
+
end
|
36
|
+
|
20
37
|
# Class full name includes the module namespace
|
21
38
|
def class_full_name
|
22
39
|
instance.class.name
|
@@ -144,17 +161,6 @@ module Peeky
|
|
144
161
|
signatures.select { |im| im.name == name && im.implementation_type == filter_type }
|
145
162
|
end
|
146
163
|
|
147
|
-
# Build (not sure where I am going with this yet)
|
148
|
-
# TODO: Refact: Currently the idea is to pre-load data
|
149
|
-
# this is slower when you are not accessing things, but
|
150
|
-
# it is easier to debug, so think about what I really want
|
151
|
-
# here
|
152
|
-
def build
|
153
|
-
ruby_instance_methods
|
154
|
-
ruby_instance_method_names
|
155
|
-
signatures
|
156
|
-
end
|
157
|
-
|
158
164
|
# Debug
|
159
165
|
#
|
160
166
|
# Refact: PATTERN: Come up it an debug inclusion system so that
|
data/lib/peeky/parameter_info.rb
CHANGED
@@ -20,11 +20,8 @@ module Peeky
|
|
20
20
|
# type of the parameter
|
21
21
|
attr_accessor :type
|
22
22
|
|
23
|
-
#
|
24
|
-
attr_accessor :
|
25
|
-
|
26
|
-
# minimal required usage in a call to the method with this paramater
|
27
|
-
attr_accessor :minimal_call_format
|
23
|
+
# default value for positional or keyed parameters
|
24
|
+
attr_accessor :default_value
|
28
25
|
|
29
26
|
def initialize(param)
|
30
27
|
map(param)
|
@@ -58,47 +55,125 @@ module Peeky
|
|
58
55
|
puts "minimal_call_format : #{minimal_call_format}"
|
59
56
|
end
|
60
57
|
|
58
|
+
# ruby code formatted for use in a method signature
|
59
|
+
def signature_format
|
60
|
+
@_signature_format ||= begin
|
61
|
+
method_name = "signature_format_#{@type}".to_sym
|
62
|
+
|
63
|
+
m = method(method_name)
|
64
|
+
m.call
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# minimal required usage in a call to the method with this paramater
|
69
|
+
def minimal_call_format
|
70
|
+
@_minimal_call_format ||= begin
|
71
|
+
method_name = "minimal_call_format_#{@type}".to_sym
|
72
|
+
|
73
|
+
if respond_to?(method_name, true)
|
74
|
+
m = method(method_name)
|
75
|
+
m.call
|
76
|
+
else
|
77
|
+
minimal_call_format_ignore
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
61
82
|
private
|
62
83
|
|
63
84
|
# Convert the limited information provided by ruby method.parameters
|
64
85
|
# to a richer structure.
|
65
|
-
# rubocop:disable Metrics/
|
86
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
66
87
|
def map(param)
|
67
88
|
@name = param.length > 1 ? param[1].to_s : ''
|
68
89
|
|
90
|
+
@default_value = nil
|
91
|
+
|
69
92
|
case param[0]
|
70
93
|
when :req
|
71
94
|
@type = :param_required
|
72
|
-
@signature_format = name.to_s
|
73
|
-
@minimal_call_format = "'#{name}'"
|
74
95
|
when :opt
|
75
96
|
@type = :param_optional
|
76
|
-
@signature_format = "#{name} = nil"
|
77
|
-
@minimal_call_format = ''
|
78
97
|
when :rest
|
79
98
|
@type = :splat
|
80
|
-
@signature_format = "*#{name}"
|
81
|
-
@minimal_call_format = ''
|
82
99
|
when :keyreq
|
83
100
|
@type = :key_required
|
84
|
-
@signature_format = "#{name}:"
|
85
|
-
@minimal_call_format = "#{name}: '#{name}'"
|
86
101
|
when :key
|
87
102
|
@type = :key_optional
|
88
|
-
@signature_format = "#{name}: nil"
|
89
|
-
@minimal_call_format = ''
|
90
103
|
when :keyrest
|
91
104
|
@type = :double_splat
|
92
|
-
@signature_format = "**#{name}"
|
93
|
-
@minimal_call_format = ''
|
94
105
|
when :block
|
95
106
|
@type = :block
|
96
|
-
@signature_format = "&#{name}"
|
97
|
-
@minimal_call_format = ''
|
98
107
|
else
|
99
108
|
raise 'unknown type'
|
100
109
|
end
|
101
110
|
end
|
102
|
-
# rubocop:enable Metrics/
|
111
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
112
|
+
|
113
|
+
# Signature format *: Is used to format a parameter when it is used
|
114
|
+
# inside of a method signature, eg. def my_method(p1, p2 = 'xyz', p3: :name_value)
|
115
|
+
|
116
|
+
def signature_format_param_required
|
117
|
+
name.to_s
|
118
|
+
end
|
119
|
+
|
120
|
+
def signature_format_param_optional
|
121
|
+
"#{name} = nil" # signature format needs to be moved to a method
|
122
|
+
end
|
123
|
+
|
124
|
+
def signature_format_splat
|
125
|
+
"*#{name}"
|
126
|
+
end
|
127
|
+
|
128
|
+
def signature_format_key_required
|
129
|
+
"#{name}:"
|
130
|
+
end
|
131
|
+
|
132
|
+
def signature_format_key_optional
|
133
|
+
"#{name}: nil"
|
134
|
+
end
|
135
|
+
|
136
|
+
def signature_format_double_splat
|
137
|
+
"**#{name}"
|
138
|
+
end
|
139
|
+
|
140
|
+
def signature_format_block
|
141
|
+
"&#{name}"
|
142
|
+
end
|
143
|
+
|
144
|
+
# Minimal call format *: Is used to format a call to a method with the least
|
145
|
+
# number of parameters needed to make it work.
|
146
|
+
|
147
|
+
def minimal_call_format_ignore
|
148
|
+
''
|
149
|
+
end
|
150
|
+
|
151
|
+
def minimal_call_format_param_required
|
152
|
+
"'#{@name}'"
|
153
|
+
end
|
154
|
+
|
155
|
+
# def minimal_call_format_param_optional
|
156
|
+
# ''
|
157
|
+
# end
|
158
|
+
|
159
|
+
# def minimal_call_format_splat
|
160
|
+
# ''
|
161
|
+
# end
|
162
|
+
|
163
|
+
def minimal_call_format_key_required
|
164
|
+
"#{@name}: '#{@name}'"
|
165
|
+
end
|
166
|
+
|
167
|
+
# def minimal_call_format_key_optional
|
168
|
+
# ''
|
169
|
+
# end
|
170
|
+
|
171
|
+
# def minimal_call_format_double_splat
|
172
|
+
# ''
|
173
|
+
# end
|
174
|
+
|
175
|
+
# def minimal_call_format_block
|
176
|
+
# ''
|
177
|
+
# end
|
103
178
|
end
|
104
179
|
end
|
@@ -122,7 +122,10 @@ module Peeky
|
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
125
|
-
|
125
|
+
if method_signature.name.to_s.end_with?('?')
|
126
|
+
result.push ''
|
127
|
+
result.push "#{@indent}# @return [Boolean] true when #{method_signature.name.to_s.humanize.downcase}"
|
128
|
+
end
|
126
129
|
|
127
130
|
render_signature = Peeky::Renderer::MethodSignatureRender.new(method_signature)
|
128
131
|
render_signature.indent = @indent
|
data/lib/peeky/version.rb
CHANGED
data/peeky.gemspec
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.31
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Cruwys
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -48,6 +48,7 @@ files:
|
|
48
48
|
- README.md
|
49
49
|
- Rakefile
|
50
50
|
- STORIES.md
|
51
|
+
- USAGE.md
|
51
52
|
- bin/console
|
52
53
|
- bin/k
|
53
54
|
- bin/kgitsync
|
@@ -85,7 +86,7 @@ rdoc_options:
|
|
85
86
|
- peeky by appydave.com
|
86
87
|
- "--main"
|
87
88
|
- README.md
|
88
|
-
- "--files STORIES.MD"
|
89
|
+
- "--files STORIES.MD USAGE.MD"
|
89
90
|
require_paths:
|
90
91
|
- lib
|
91
92
|
required_ruby_version: !ruby/object:Gem::Requirement
|