peeky 0.0.27 → 0.0.40
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/.github/workflows/ruby.yml +2 -3
- data/.rubocop.yml +8 -3
- data/CODE_OF_CONDUCT.md +1 -1
- data/Gemfile +15 -9
- data/Guardfile +4 -4
- data/README.md +96 -5
- data/Rakefile +15 -0
- data/{README-stories.md → STORIES.md} +11 -15
- data/USAGE.md +438 -0
- data/USAGE2.md +5 -0
- data/lib/peeky.rb +3 -0
- data/lib/peeky/api.rb +19 -2
- data/lib/peeky/attr_info.rb +4 -0
- data/lib/peeky/class_info.rb +40 -36
- data/lib/peeky/example/yard_sample.rb +33 -10
- data/lib/peeky/method_info.rb +106 -27
- data/lib/peeky/parameter_info.rb +102 -26
- data/lib/peeky/renderer/class_debug_render.rb +95 -0
- data/lib/peeky/renderer/class_interface_yard_render.rb +8 -8
- data/lib/peeky/renderer/method_call_minimum_params_render.rb +7 -3
- data/lib/peeky/version.rb +1 -1
- data/peeky.gemspec +11 -17
- metadata +19 -12
@@ -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 #{'-' * 86}")
|
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 #{'-' * 82}")
|
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 = 24)
|
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
|
+
'-' * 100,
|
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')} #{lj('default')}",
|
86
|
+
'-' * 100
|
87
|
+
]
|
88
|
+
|
89
|
+
result + parameters.map do |param|
|
90
|
+
"#{lj(param.name)} #{lj(param.signature_format)} #{lj(param.type)} #{lj(param.default_value)}"
|
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]
|
@@ -112,17 +108,21 @@ module Peeky
|
|
112
108
|
when :key_required
|
113
109
|
result.push "#{@indent}# @param #{parameter.name} [#{default_param_type}] #{parameter.name}: <value for #{parameter.name.to_s.humanize.downcase}> (required)"
|
114
110
|
when :key_optional
|
115
|
-
result.push "#{@indent}# @param #{parameter.name} [#{
|
111
|
+
result.push "#{@indent}# @param #{parameter.name} [#{parameter.default_value_type}] #{parameter.name}: is optional, defaults to #{parameter.wrap_default_value('nil')}"
|
116
112
|
when :param_required
|
117
113
|
result.push "#{@indent}# @param #{parameter.name} [#{default_param_type}] #{parameter.name.to_s.humanize.downcase} (required)"
|
118
114
|
when :param_optional
|
119
|
-
result.push "#{@indent}# @param #{parameter.name} [#{
|
115
|
+
result.push "#{@indent}# @param #{parameter.name} [#{parameter.default_value_type}] #{parameter.name} is optional, defaults to #{parameter.wrap_default_value('nil')}"
|
116
|
+
# result.push "#{@indent}# @param #{parameter.name} [#{default_param_type}] #{parameter.name.to_s.humanize.downcase} (optional)"
|
120
117
|
else
|
121
118
|
result.push "#{@indent}# @param #{parameter.name} [#{default_param_type}] #{parameter.name.to_s.humanize.downcase}"
|
122
119
|
end
|
123
120
|
end
|
124
121
|
|
125
|
-
|
122
|
+
if method_signature.name.to_s.end_with?('?')
|
123
|
+
result.push ''
|
124
|
+
result.push "#{@indent}# @return [Boolean] true when #{method_signature.name.to_s.humanize.downcase}"
|
125
|
+
end
|
126
126
|
|
127
127
|
render_signature = Peeky::Renderer::MethodSignatureRender.new(method_signature)
|
128
128
|
render_signature.indent = @indent
|
@@ -12,8 +12,8 @@ module Peeky
|
|
12
12
|
attr_reader :method_signature
|
13
13
|
|
14
14
|
def initialize(method_signature, **opts)
|
15
|
-
instance_name = opts[:instance_name] || 'instance'
|
16
|
-
@instance_name = instance_name
|
15
|
+
# instance_name = opts[:instance_name] || 'instance'
|
16
|
+
@instance_name = opts[:instance_name]
|
17
17
|
@method_signature = method_signature
|
18
18
|
end
|
19
19
|
|
@@ -29,7 +29,11 @@ module Peeky
|
|
29
29
|
|
30
30
|
params = minimal_call_parameters.length.zero? ? '' : "(#{minimal_call_parameters})"
|
31
31
|
|
32
|
-
|
32
|
+
if @instance_name.nil?
|
33
|
+
"#{name}#{params}"
|
34
|
+
else
|
35
|
+
"#{@instance_name}.#{name}#{params}"
|
36
|
+
end
|
33
37
|
end
|
34
38
|
end
|
35
39
|
end
|
data/lib/peeky/version.rb
CHANGED
data/peeky.gemspec
CHANGED
@@ -3,25 +3,16 @@
|
|
3
3
|
require_relative 'lib/peeky/version'
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
|
-
spec.required_ruby_version = '>= 2.5'
|
7
6
|
spec.name = 'peeky'
|
8
7
|
spec.version = Peeky::VERSION
|
9
8
|
spec.authors = ['David Cruwys']
|
10
9
|
spec.email = ['david@ideasmen.com.au']
|
11
10
|
|
12
|
-
spec.summary = '
|
13
|
-
spec.description =
|
14
|
-
Peeky is a Ruby GEM for peaking into ruby classes and extracting meta data.
|
15
|
-
You can use this meta data to recreate classes, interfaces, documentation etc.
|
16
|
-
or use it just to understand the internals of a class.
|
17
|
-
TEXT
|
18
|
-
|
11
|
+
spec.summary = 'Take a peek into your ruby classes and extract useful meta data'
|
12
|
+
spec.description = 'peeky'
|
19
13
|
spec.homepage = 'http://appydave.com/gems/peeky'
|
20
14
|
spec.license = 'MIT'
|
21
|
-
|
22
|
-
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
23
|
-
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
24
|
-
raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.' unless spec.respond_to?(:metadata)
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
|
25
16
|
|
26
17
|
# spec.metadata['allowed_push_host'] = "Set to 'http://mygemserver.com'"
|
27
18
|
|
@@ -32,20 +23,23 @@ Gem::Specification.new do |spec|
|
|
32
23
|
# Click Add Project:
|
33
24
|
# git@github.com:klueless-io/peeky
|
34
25
|
spec.metadata['documentation_uri'] = 'https://rubydoc.info/github/klueless-io/peeky/master'
|
35
|
-
spec.extra_rdoc_files = ['README-stories.md', 'README-stories.md']
|
36
26
|
|
37
27
|
# Specify which files should be added to the gem when it is released.
|
38
28
|
# The `git ls-files -z` loads the RubyGem files that have been added into git.
|
39
29
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
40
|
-
`git ls-files -z`.split("\x0").reject
|
41
|
-
f.match(%r{^(test|spec|features)/})
|
42
|
-
end
|
30
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
43
31
|
end
|
44
32
|
spec.bindir = 'exe'
|
45
33
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
46
34
|
spec.require_paths = ['lib']
|
35
|
+
|
47
36
|
# spec.extensions = ['ext/peeky/extconf.rb']
|
37
|
+
spec.extra_rdoc_files = ['README.md', 'STORIES.md', 'USAGE.md']
|
38
|
+
spec.rdoc_options += [
|
39
|
+
'--title', 'peeky by appydave.com',
|
40
|
+
'--main', 'README.md',
|
41
|
+
'--files STORIES.MD USAGE.MD'
|
42
|
+
]
|
48
43
|
|
49
44
|
spec.add_dependency 'activesupport'
|
50
|
-
# spec.add_dependency 'tty-box', '~> 0.5.0'
|
51
45
|
end
|
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.40
|
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: 2021-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -24,16 +24,15 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
description:
|
28
|
-
Peeky is a Ruby GEM for peaking into ruby classes and extracting meta data.
|
29
|
-
You can use this meta data to recreate classes, interfaces, documentation etc.
|
30
|
-
or use it just to understand the internals of a class.
|
27
|
+
description: peeky
|
31
28
|
email:
|
32
29
|
- david@ideasmen.com.au
|
33
30
|
executables: []
|
34
31
|
extensions: []
|
35
32
|
extra_rdoc_files:
|
36
|
-
- README
|
33
|
+
- README.md
|
34
|
+
- STORIES.md
|
35
|
+
- USAGE.md
|
37
36
|
files:
|
38
37
|
- ".github/workflows/ruby.yml"
|
39
38
|
- ".gitignore"
|
@@ -44,9 +43,11 @@ files:
|
|
44
43
|
- Gemfile
|
45
44
|
- Guardfile
|
46
45
|
- LICENSE.txt
|
47
|
-
- README-stories.md
|
48
46
|
- README.md
|
49
47
|
- Rakefile
|
48
|
+
- STORIES.md
|
49
|
+
- USAGE.md
|
50
|
+
- USAGE2.md
|
50
51
|
- bin/console
|
51
52
|
- bin/k
|
52
53
|
- bin/kgitsync
|
@@ -63,6 +64,7 @@ files:
|
|
63
64
|
- lib/peeky/parameter_info.rb
|
64
65
|
- lib/peeky/predicates/attr_reader_predicate.rb
|
65
66
|
- lib/peeky/predicates/attr_writer_predicate.rb
|
67
|
+
- lib/peeky/renderer/class_debug_render.rb
|
66
68
|
- lib/peeky/renderer/class_interface_render.rb
|
67
69
|
- lib/peeky/renderer/class_interface_yard_render.rb
|
68
70
|
- lib/peeky/renderer/method_call_minimum_params_render.rb
|
@@ -79,22 +81,27 @@ metadata:
|
|
79
81
|
changelog_uri: https://github.com/klueless-io/peeky/commits/master
|
80
82
|
documentation_uri: https://rubydoc.info/github/klueless-io/peeky/master
|
81
83
|
post_install_message:
|
82
|
-
rdoc_options:
|
84
|
+
rdoc_options:
|
85
|
+
- "--title"
|
86
|
+
- peeky by appydave.com
|
87
|
+
- "--main"
|
88
|
+
- README.md
|
89
|
+
- "--files STORIES.MD USAGE.MD"
|
83
90
|
require_paths:
|
84
91
|
- lib
|
85
92
|
required_ruby_version: !ruby/object:Gem::Requirement
|
86
93
|
requirements:
|
87
94
|
- - ">="
|
88
95
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
96
|
+
version: 2.4.0
|
90
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
98
|
requirements:
|
92
99
|
- - ">="
|
93
100
|
- !ruby/object:Gem::Version
|
94
101
|
version: '0'
|
95
102
|
requirements: []
|
96
|
-
rubygems_version: 3.
|
103
|
+
rubygems_version: 3.2.7
|
97
104
|
signing_key:
|
98
105
|
specification_version: 4
|
99
|
-
summary:
|
106
|
+
summary: Take a peek into your ruby classes and extract useful meta data
|
100
107
|
test_files: []
|