peeky 0.0.25 → 0.0.39
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +2 -3
- data/.rubocop.yml +10 -2
- data/CODE_OF_CONDUCT.md +1 -1
- data/Gemfile +12 -6
- data/Guardfile +4 -4
- data/README.md +96 -5
- data/{README-stories.md → STORIES.md} +11 -15
- data/USAGE.md +438 -0
- data/USAGE2.md +5 -0
- data/lib/peeky.rb +1 -0
- data/lib/peeky/api.rb +19 -2
- data/lib/peeky/attr_info.rb +4 -0
- data/lib/peeky/class_info.rb +43 -39
- data/lib/peeky/example/yard_sample.rb +27 -10
- data/lib/peeky/method_info.rb +106 -27
- data/lib/peeky/parameter_info.rb +102 -26
- data/lib/peeky/predicates/attr_reader_predicate.rb +1 -1
- 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 -16
- metadata +20 -13
- data/lib/peeky/tools/generate_yard_documentation.rb +0 -19
@@ -20,7 +20,7 @@ module Peeky
|
|
20
20
|
# Really need to handle exceptions and types better
|
21
21
|
# old_value = instance.send(method_name)
|
22
22
|
|
23
|
-
# This code works by
|
23
|
+
# This code works by
|
24
24
|
# 1. Set @name_of_method variable to random value
|
25
25
|
# 2. Call method name and see if it returns that value
|
26
26
|
# 3. Return match<true> if the values are equal
|
@@ -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,15 +23,19 @@ Gem::Specification.new do |spec|
|
|
32
23
|
# Specify which files should be added to the gem when it is released.
|
33
24
|
# The `git ls-files -z` loads the RubyGem files that have been added into git.
|
34
25
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
35
|
-
`git ls-files -z`.split("\x0").reject
|
36
|
-
f.match(%r{^(test|spec|features)/})
|
37
|
-
end
|
26
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
38
27
|
end
|
39
28
|
spec.bindir = 'exe'
|
40
29
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
41
30
|
spec.require_paths = ['lib']
|
31
|
+
|
42
32
|
# spec.extensions = ['ext/peeky/extconf.rb']
|
33
|
+
spec.extra_rdoc_files = ['README.md', 'STORIES.md', 'USAGE.md']
|
34
|
+
spec.rdoc_options += [
|
35
|
+
'--title', 'peeky by appydave.com',
|
36
|
+
'--main', 'README.md',
|
37
|
+
'--files STORIES.MD USAGE.MD'
|
38
|
+
]
|
43
39
|
|
44
40
|
spec.add_dependency 'activesupport'
|
45
|
-
# spec.add_dependency 'tty-box', '~> 0.5.0'
|
46
41
|
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.39
|
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-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -24,15 +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
|
-
extra_rdoc_files:
|
32
|
+
extra_rdoc_files:
|
33
|
+
- README.md
|
34
|
+
- STORIES.md
|
35
|
+
- USAGE.md
|
36
36
|
files:
|
37
37
|
- ".github/workflows/ruby.yml"
|
38
38
|
- ".gitignore"
|
@@ -43,9 +43,11 @@ files:
|
|
43
43
|
- Gemfile
|
44
44
|
- Guardfile
|
45
45
|
- LICENSE.txt
|
46
|
-
- README-stories.md
|
47
46
|
- README.md
|
48
47
|
- Rakefile
|
48
|
+
- STORIES.md
|
49
|
+
- USAGE.md
|
50
|
+
- USAGE2.md
|
49
51
|
- bin/console
|
50
52
|
- bin/k
|
51
53
|
- bin/kgitsync
|
@@ -62,12 +64,12 @@ files:
|
|
62
64
|
- lib/peeky/parameter_info.rb
|
63
65
|
- lib/peeky/predicates/attr_reader_predicate.rb
|
64
66
|
- lib/peeky/predicates/attr_writer_predicate.rb
|
67
|
+
- lib/peeky/renderer/class_debug_render.rb
|
65
68
|
- lib/peeky/renderer/class_interface_render.rb
|
66
69
|
- lib/peeky/renderer/class_interface_yard_render.rb
|
67
70
|
- lib/peeky/renderer/method_call_minimum_params_render.rb
|
68
71
|
- lib/peeky/renderer/method_signature_render.rb
|
69
72
|
- lib/peeky/renderer/method_signature_with_debug_render.rb
|
70
|
-
- lib/peeky/tools/generate_yard_documentation.rb
|
71
73
|
- lib/peeky/version.rb
|
72
74
|
- peeky.gemspec
|
73
75
|
homepage: http://appydave.com/gems/peeky
|
@@ -78,22 +80,27 @@ metadata:
|
|
78
80
|
source_code_uri: https://github.com/klueless-io/peeky
|
79
81
|
changelog_uri: https://github.com/klueless-io/peeky/commits/master
|
80
82
|
post_install_message:
|
81
|
-
rdoc_options:
|
83
|
+
rdoc_options:
|
84
|
+
- "--title"
|
85
|
+
- peeky by appydave.com
|
86
|
+
- "--main"
|
87
|
+
- README.md
|
88
|
+
- "--files STORIES.MD USAGE.MD"
|
82
89
|
require_paths:
|
83
90
|
- lib
|
84
91
|
required_ruby_version: !ruby/object:Gem::Requirement
|
85
92
|
requirements:
|
86
93
|
- - ">="
|
87
94
|
- !ruby/object:Gem::Version
|
88
|
-
version:
|
95
|
+
version: 2.4.0
|
89
96
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
97
|
requirements:
|
91
98
|
- - ">="
|
92
99
|
- !ruby/object:Gem::Version
|
93
100
|
version: '0'
|
94
101
|
requirements: []
|
95
|
-
rubygems_version: 3.
|
102
|
+
rubygems_version: 3.2.7
|
96
103
|
signing_key:
|
97
104
|
specification_version: 4
|
98
|
-
summary:
|
105
|
+
summary: Take a peek into your ruby classes and extract useful meta data
|
99
106
|
test_files: []
|