peeky 0.0.31 → 0.0.33
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/.rubocop.yml +3 -1
- data/README.md +29 -3
- data/USAGE.md +116 -0
- data/lib/peeky.rb +1 -0
- data/lib/peeky/api.rb +2 -0
- data/lib/peeky/renderer/class_debug_render.rb +95 -0
- data/lib/peeky/renderer/class_interface_yard_render.rb +1 -5
- data/lib/peeky/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f39a9477e701fff31e203e1d90fb479cd8898662499edf4c4722673e7c0da20
|
4
|
+
data.tar.gz: d7a743fc208c5dbfe640c687833e3cc69b663654630cad0d15a582033f3f39f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd1a24d91ef1fef5b72fc90f2c041112462cc842009ed68f9499f9a94cc3218ff0e2a0bc46ba4b5564487891b54d2bff023cf4deaa8af64a607f207b4f6a8e6f
|
7
|
+
data.tar.gz: 8fe132fffb24332d7b28b92a288b799ed51dac71df7bcfb8887bec7c6433c3b58bda9a6af05cb81dc006322b5991b6b05735760756dcef4c8919575e16155bd8
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -40,7 +40,7 @@ See all [stories](./STORIES.md)
|
|
40
40
|
|
41
41
|
## Usage
|
42
42
|
|
43
|
-
See all [
|
43
|
+
See all [usage examples](./USAGE.md)
|
44
44
|
|
45
45
|
### Basic Example
|
46
46
|
|
@@ -104,6 +104,32 @@ class SimpleClass
|
|
104
104
|
end
|
105
105
|
```
|
106
106
|
|
107
|
+
#### Class debug
|
108
|
+
Render debug information
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
puts api.render_class(:class_debug, instance: Sample::SimpleClass.new)
|
112
|
+
```
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
```text
|
117
|
+
----------------------------------------------------------------------
|
118
|
+
class name : SimpleClass
|
119
|
+
module name : Sample
|
120
|
+
class full name : Sample::SimpleClass
|
121
|
+
|
122
|
+
-- Attributes --------------------------------------------------------
|
123
|
+
attr_accessor : read_write
|
124
|
+
|
125
|
+
-- Public Methods ----------------------------------------------------
|
126
|
+
position_and_optional::
|
127
|
+
name param format type
|
128
|
+
----------------------------------------------------------------------
|
129
|
+
aaa aaa param_required
|
130
|
+
bbb bbb = nil param_optional
|
131
|
+
```
|
132
|
+
|
107
133
|
|
108
134
|
|
109
135
|
|
@@ -115,7 +141,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
115
141
|
|
116
142
|
## Contributing
|
117
143
|
|
118
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
144
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/klueless-io/peeky. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
119
145
|
|
120
146
|
## License
|
121
147
|
|
@@ -123,7 +149,7 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
123
149
|
|
124
150
|
## Code of Conduct
|
125
151
|
|
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/
|
152
|
+
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/klueless-io/peeky/blob/master/CODE_OF_CONDUCT.md).
|
127
153
|
|
128
154
|
## Copyright
|
129
155
|
|
data/USAGE.md
CHANGED
@@ -320,3 +320,119 @@ end
|
|
320
320
|
```
|
321
321
|
|
322
322
|
#### Debug class info
|
323
|
+
Render debug information on complex class
|
324
|
+
|
325
|
+
```ruby
|
326
|
+
puts api.render_class(:class_debug, instance: Sample::ComplexClass.new)
|
327
|
+
```
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
```text
|
332
|
+
----------------------------------------------------------------------
|
333
|
+
class name : ComplexClass
|
334
|
+
module name : Sample
|
335
|
+
class full name : Sample::ComplexClass
|
336
|
+
|
337
|
+
-- Attributes --------------------------------------------------------
|
338
|
+
attr_accessor : a_read_write1
|
339
|
+
attr_accessor : a_read_write2
|
340
|
+
attr_reader : b_another_reader
|
341
|
+
attr_reader : b_reader
|
342
|
+
attr_reader : looks_like_an_attr_reader
|
343
|
+
attr_writer : c_another_writer
|
344
|
+
attr_writer : c_writer
|
345
|
+
|
346
|
+
-- Public Methods ----------------------------------------------------
|
347
|
+
alpha_sort1::
|
348
|
+
name param format type
|
349
|
+
----------------------------------------------------------------------
|
350
|
+
|
351
|
+
alpha_sort2::
|
352
|
+
name param format type
|
353
|
+
----------------------------------------------------------------------
|
354
|
+
|
355
|
+
destructive!::
|
356
|
+
name param format type
|
357
|
+
----------------------------------------------------------------------
|
358
|
+
|
359
|
+
do_something_method::
|
360
|
+
name param format type
|
361
|
+
----------------------------------------------------------------------
|
362
|
+
|
363
|
+
method_01::
|
364
|
+
name param format type
|
365
|
+
----------------------------------------------------------------------
|
366
|
+
aaa aaa param_required
|
367
|
+
|
368
|
+
method_02::
|
369
|
+
name param format type
|
370
|
+
----------------------------------------------------------------------
|
371
|
+
aaa aaa param_required
|
372
|
+
bbb bbb = nil param_optional
|
373
|
+
|
374
|
+
method_03::
|
375
|
+
name param format type
|
376
|
+
----------------------------------------------------------------------
|
377
|
+
aaa aaa param_required
|
378
|
+
bbb bbb = nil param_optional
|
379
|
+
ccc ccc = nil param_optional
|
380
|
+
|
381
|
+
method_04::
|
382
|
+
name param format type
|
383
|
+
----------------------------------------------------------------------
|
384
|
+
aaa *aaa splat
|
385
|
+
|
386
|
+
method_05::
|
387
|
+
name param format type
|
388
|
+
----------------------------------------------------------------------
|
389
|
+
aaa aaa param_required
|
390
|
+
bbb bbb = nil param_optional
|
391
|
+
ccc *ccc splat
|
392
|
+
|
393
|
+
method_06::
|
394
|
+
name param format type
|
395
|
+
----------------------------------------------------------------------
|
396
|
+
aaa **aaa double_splat
|
397
|
+
|
398
|
+
method_07::
|
399
|
+
name param format type
|
400
|
+
----------------------------------------------------------------------
|
401
|
+
aaa aaa param_required
|
402
|
+
bbb *bbb splat
|
403
|
+
ccc **ccc double_splat
|
404
|
+
|
405
|
+
method_08::
|
406
|
+
name param format type
|
407
|
+
----------------------------------------------------------------------
|
408
|
+
aaa aaa param_required
|
409
|
+
bbb *bbb splat
|
410
|
+
ccc **ccc double_splat
|
411
|
+
ddd &ddd block
|
412
|
+
|
413
|
+
method_09::
|
414
|
+
name param format type
|
415
|
+
----------------------------------------------------------------------
|
416
|
+
aaa aaa: key_required
|
417
|
+
|
418
|
+
method_10::
|
419
|
+
name param format type
|
420
|
+
----------------------------------------------------------------------
|
421
|
+
aaa aaa: key_required
|
422
|
+
bbb bbb: nil key_optional
|
423
|
+
|
424
|
+
method_with_every_type_of_paramater::
|
425
|
+
name param format type
|
426
|
+
----------------------------------------------------------------------
|
427
|
+
aaa aaa param_required
|
428
|
+
bbb bbb = nil param_optional
|
429
|
+
ccc *ccc splat
|
430
|
+
ddd ddd: key_required
|
431
|
+
eee eee: nil key_optional
|
432
|
+
fff **fff double_splat
|
433
|
+
ggg &ggg block
|
434
|
+
|
435
|
+
questionable?::
|
436
|
+
name param format type
|
437
|
+
----------------------------------------------------------------------
|
438
|
+
```
|
data/lib/peeky.rb
CHANGED
@@ -12,6 +12,7 @@ require 'peeky/parameter_info'
|
|
12
12
|
require 'peeky/predicates/attr_reader_predicate'
|
13
13
|
require 'peeky/predicates/attr_writer_predicate'
|
14
14
|
|
15
|
+
require 'peeky/renderer/class_debug_render'
|
15
16
|
require 'peeky/renderer/class_interface_render'
|
16
17
|
require 'peeky/renderer/class_interface_yard_render'
|
17
18
|
require 'peeky/renderer/method_call_minimum_params_render'
|
data/lib/peeky/api.rb
CHANGED
@@ -0,0 +1,95 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Peeky
|
4
|
+
module Renderer
|
5
|
+
# Class Debug Render
|
6
|
+
class ClassDebugRender
|
7
|
+
attr_reader :class_info
|
8
|
+
|
9
|
+
def initialize(class_info)
|
10
|
+
@key_width = 30
|
11
|
+
@class_info = class_info
|
12
|
+
end
|
13
|
+
|
14
|
+
# Render the class interface
|
15
|
+
# rubocop:disable Metrics/AbcSize
|
16
|
+
def render
|
17
|
+
output = []
|
18
|
+
output.push class_details
|
19
|
+
attributes = render_accessors + render_readers + render_writers
|
20
|
+
|
21
|
+
if attributes.length.positive?
|
22
|
+
output.push("-- Attributes #{'-' * 56}")
|
23
|
+
output.push(*attributes)
|
24
|
+
output.push('')
|
25
|
+
end
|
26
|
+
|
27
|
+
methods = render_methods
|
28
|
+
|
29
|
+
if methods.length.positive?
|
30
|
+
output.push("-- Public Methods #{'-' * 52}")
|
31
|
+
output.push(*methods)
|
32
|
+
output.push('')
|
33
|
+
end
|
34
|
+
|
35
|
+
output.pop if output.last == ''
|
36
|
+
|
37
|
+
output.join("\n")
|
38
|
+
end
|
39
|
+
# rubocop:enable Metrics/AbcSize
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def lj(value, size = 20)
|
44
|
+
value.to_s.ljust(size)
|
45
|
+
end
|
46
|
+
|
47
|
+
def kv(key, value)
|
48
|
+
"#{key.to_s.ljust(@key_width)}: #{value}"
|
49
|
+
end
|
50
|
+
|
51
|
+
def class_details
|
52
|
+
[
|
53
|
+
'-' * 70,
|
54
|
+
kv('class name', @class_info.class_name),
|
55
|
+
kv('module name', @class_info.module_name),
|
56
|
+
kv('class full name', @class_info.class_full_name),
|
57
|
+
''
|
58
|
+
]
|
59
|
+
end
|
60
|
+
|
61
|
+
def render_accessors
|
62
|
+
@class_info.accessors.map { |attr| kv('attr_accessor', attr.name) }
|
63
|
+
end
|
64
|
+
|
65
|
+
def render_readers
|
66
|
+
@class_info.readers.map { |attr| kv('attr_reader', attr.name) }
|
67
|
+
end
|
68
|
+
|
69
|
+
def render_writers
|
70
|
+
@class_info.writers.map { |attr| kv('attr_writer', attr.name) }
|
71
|
+
end
|
72
|
+
|
73
|
+
def render_methods
|
74
|
+
@class_info.methods.flat_map do |method|
|
75
|
+
[
|
76
|
+
"#{method.name}::",
|
77
|
+
*render_paramaters(method.parameters),
|
78
|
+
''
|
79
|
+
]
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def render_paramaters(parameters)
|
84
|
+
result = [
|
85
|
+
"#{lj('name')} #{lj('param format')} #{lj('type')}",
|
86
|
+
'-' * 70
|
87
|
+
]
|
88
|
+
|
89
|
+
result + parameters.map do |param|
|
90
|
+
"#{lj(param.name)} #{lj(param.signature_format)} #{lj(param.type)}"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# require 'active_support/core_ext'
|
4
3
|
require 'active_support/core_ext/string'
|
5
4
|
|
6
5
|
module Peeky
|
@@ -37,10 +36,7 @@ module Peeky
|
|
37
36
|
output = []
|
38
37
|
output.push render_start
|
39
38
|
@indent += ' '
|
40
|
-
output += render_accessors
|
41
|
-
output += render_readers
|
42
|
-
output += render_writers
|
43
|
-
output += render_methods
|
39
|
+
output += (render_accessors + render_readers + render_writers + render_methods)
|
44
40
|
output.pop if output.last == ''
|
45
41
|
|
46
42
|
@indent = @indent[0..-3]
|
data/lib/peeky/version.rb
CHANGED
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.
|
4
|
+
version: 0.0.33
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Cruwys
|
@@ -65,6 +65,7 @@ files:
|
|
65
65
|
- lib/peeky/parameter_info.rb
|
66
66
|
- lib/peeky/predicates/attr_reader_predicate.rb
|
67
67
|
- lib/peeky/predicates/attr_writer_predicate.rb
|
68
|
+
- lib/peeky/renderer/class_debug_render.rb
|
68
69
|
- lib/peeky/renderer/class_interface_render.rb
|
69
70
|
- lib/peeky/renderer/class_interface_yard_render.rb
|
70
71
|
- lib/peeky/renderer/method_call_minimum_params_render.rb
|