peeky 0.0.14 → 0.0.28
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 +31 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +19 -0
- data/.rubocop_todo.yml +4 -0
- data/CODE_OF_CONDUCT.md +1 -1
- data/Gemfile +6 -3
- data/Guardfile +4 -4
- data/README.md +12 -32
- data/STORIES.md +83 -0
- data/lib/peeky.rb +3 -0
- data/lib/peeky/api.rb +70 -0
- data/lib/peeky/class_info.rb +133 -29
- data/lib/peeky/example/yard_sample.rb +123 -0
- data/lib/peeky/method_info.rb +7 -5
- data/lib/peeky/predicates/attr_reader_predicate.rb +16 -4
- data/lib/peeky/predicates/attr_writer_predicate.rb +8 -0
- data/lib/peeky/renderer/class_interface_render.rb +10 -10
- data/lib/peeky/renderer/class_interface_yard_render.rb +142 -0
- data/lib/peeky/renderer/method_call_minimum_params_render.rb +4 -5
- data/lib/peeky/renderer/method_signature_render.rb +44 -13
- data/lib/peeky/renderer/method_signature_with_debug_render.rb +11 -11
- data/lib/peeky/version.rb +1 -1
- data/peeky.gemspec +21 -4
- metadata +38 -8
@@ -4,14 +4,54 @@ module Peeky
|
|
4
4
|
module Renderer
|
5
5
|
# Render: Method Signature in compact format
|
6
6
|
#
|
7
|
-
# Example output:
|
7
|
+
# === Example output (:default):
|
8
|
+
# def simple(first_param)
|
9
|
+
# end
|
10
|
+
#
|
11
|
+
# def complex(aaa, bbb = nil, *ccc, ddd:, eee: nil, **fff, &ggg)
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# === Example output (:compact):
|
8
15
|
# def simple(first_param); end
|
9
16
|
# def complex(aaa, bbb = nil, *ccc, ddd:, eee: nil, **fff, &ggg); end
|
10
17
|
class MethodSignatureRender
|
18
|
+
# Indentation prefix as a string.
|
19
|
+
#
|
20
|
+
# Defaults to ''
|
21
|
+
#
|
22
|
+
# If you were writing a class into a file with an existing
|
23
|
+
# module, you may set the indent to ' ' if you wanted this
|
24
|
+
# render to indent by two spaces
|
25
|
+
attr_accessor :indent
|
26
|
+
|
27
|
+
# Style of method rendering [:default, :compact]
|
28
|
+
#
|
29
|
+
# default:: will render +def method_name+ and +end+ on separate lines
|
30
|
+
# compact:: will render +def method_name+ and +end+ on same line
|
31
|
+
# @return [Symbol] style
|
32
|
+
attr_accessor :style
|
33
|
+
|
34
|
+
# Method signature stores a MethodInfo object
|
11
35
|
attr_reader :method_signature
|
12
36
|
|
13
|
-
def initialize(method_signature)
|
37
|
+
def initialize(method_signature, **_opts)
|
14
38
|
@method_signature = method_signature
|
39
|
+
@indent = ''
|
40
|
+
@style = :compact
|
41
|
+
end
|
42
|
+
|
43
|
+
# Render the method signature in the selected style
|
44
|
+
def render
|
45
|
+
output = []
|
46
|
+
if @style == :compact
|
47
|
+
signature = "#{render_signature};"
|
48
|
+
output.push "#{signature.ljust(80)}#{render_end}"
|
49
|
+
end
|
50
|
+
if @style == :default
|
51
|
+
output.push render_signature
|
52
|
+
output.push render_end
|
53
|
+
end
|
54
|
+
output.join("\n")
|
15
55
|
end
|
16
56
|
|
17
57
|
def render_signature
|
@@ -19,20 +59,11 @@ module Peeky
|
|
19
59
|
|
20
60
|
formatted_parameters = method_signature.parameters.map(&:signature_format).join(', ')
|
21
61
|
params = formatted_parameters.length.zero? ? '' : "(#{formatted_parameters})"
|
22
|
-
"def #{name}#{params}"
|
62
|
+
"#{@indent}def #{name}#{params}"
|
23
63
|
end
|
24
64
|
|
25
65
|
def render_end
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
def render
|
30
|
-
signature = "#{render_signature};"
|
31
|
-
"#{signature.ljust(80)}#{render_end}"
|
32
|
-
end
|
33
|
-
|
34
|
-
def debug
|
35
|
-
puts render
|
66
|
+
"#{@indent}end"
|
36
67
|
end
|
37
68
|
end
|
38
69
|
end
|
@@ -22,14 +22,22 @@ module Peeky
|
|
22
22
|
# puts ggg # &ggg is block with many calling options, example - instance_eval(&block) if block_given?
|
23
23
|
# end
|
24
24
|
class MethodSignatureWithDebugRender
|
25
|
+
# Method signature stores a MethodInfo object
|
25
26
|
attr_reader :method_signature
|
26
27
|
|
27
|
-
def initialize(method_signature)
|
28
|
+
def initialize(method_signature, **_opts)
|
28
29
|
@method_signature = method_signature
|
29
30
|
|
30
31
|
@render_signature = Peeky::Renderer::MethodSignatureRender.new(method_signature)
|
31
32
|
end
|
32
33
|
|
34
|
+
# Render the method with debug statements for each parameter
|
35
|
+
def render
|
36
|
+
render_method
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
33
41
|
def render_method
|
34
42
|
name = method_signature.name
|
35
43
|
|
@@ -38,7 +46,7 @@ module Peeky
|
|
38
46
|
indent = ' '
|
39
47
|
output += "#{indent}puts 'method name: #{name}'\n"
|
40
48
|
|
41
|
-
output +=
|
49
|
+
output += render_debug_logic(indent, 30)
|
42
50
|
|
43
51
|
indent = ''
|
44
52
|
output += "#{indent}#{@render_signature.render_end}\n"
|
@@ -47,7 +55,7 @@ module Peeky
|
|
47
55
|
end
|
48
56
|
|
49
57
|
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
50
|
-
def
|
58
|
+
def render_debug_logic(indent, size)
|
51
59
|
output = ''
|
52
60
|
method_signature.parameters.each do |parameter|
|
53
61
|
line = ''
|
@@ -73,14 +81,6 @@ module Peeky
|
|
73
81
|
output
|
74
82
|
end
|
75
83
|
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
76
|
-
|
77
|
-
def render
|
78
|
-
render_method
|
79
|
-
end
|
80
|
-
|
81
|
-
def debug
|
82
|
-
puts render
|
83
|
-
end
|
84
84
|
end
|
85
85
|
end
|
86
86
|
end
|
data/lib/peeky/version.rb
CHANGED
data/peeky.gemspec
CHANGED
@@ -3,14 +3,20 @@
|
|
3
3
|
require_relative 'lib/peeky/version'
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
|
+
# https://piotrmurach.com/articles/writing-a-ruby-gem-specification/
|
6
7
|
spec.required_ruby_version = '>= 2.5'
|
7
8
|
spec.name = 'peeky'
|
8
9
|
spec.version = Peeky::VERSION
|
9
|
-
spec.authors = ['David']
|
10
|
+
spec.authors = ['David Cruwys']
|
10
11
|
spec.email = ['david@ideasmen.com.au']
|
11
12
|
|
12
|
-
spec.summary = '
|
13
|
-
spec.description =
|
13
|
+
spec.summary = 'Take a peek into your ruby classes and extract useful meta data'
|
14
|
+
spec.description = <<-TEXT
|
15
|
+
Peeky is a Ruby GEM for peaking into ruby classes and extracting meta data.
|
16
|
+
You can use this meta data to recreate classes, interfaces, documentation etc.
|
17
|
+
or use it just to understand the internals of a class.
|
18
|
+
TEXT
|
19
|
+
|
14
20
|
spec.homepage = 'http://appydave.com/gems/peeky'
|
15
21
|
spec.license = 'MIT'
|
16
22
|
|
@@ -23,6 +29,10 @@ Gem::Specification.new do |spec|
|
|
23
29
|
spec.metadata['homepage_uri'] = spec.homepage
|
24
30
|
spec.metadata['source_code_uri'] = 'https://github.com/klueless-io/peeky'
|
25
31
|
spec.metadata['changelog_uri'] = 'https://github.com/klueless-io/peeky/commits/master'
|
32
|
+
# Go to: https://rubydoc.info/
|
33
|
+
# Click Add Project:
|
34
|
+
# git@github.com:klueless-io/peeky
|
35
|
+
spec.metadata['documentation_uri'] = 'https://rubydoc.info/github/klueless-io/peeky/master'
|
26
36
|
|
27
37
|
# Specify which files should be added to the gem when it is released.
|
28
38
|
# The `git ls-files -z` loads the RubyGem files that have been added into git.
|
@@ -35,6 +45,13 @@ Gem::Specification.new do |spec|
|
|
35
45
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
36
46
|
spec.require_paths = ['lib']
|
37
47
|
# spec.extensions = ['ext/peeky/extconf.rb']
|
38
|
-
|
48
|
+
spec.extra_rdoc_files = ['README.md', 'STORIES.md']
|
49
|
+
spec.rdoc_options += [
|
50
|
+
'--title', 'peeky by appydave.com',
|
51
|
+
'--main', 'README.md',
|
52
|
+
'--files STORIES.MD'
|
53
|
+
]
|
54
|
+
|
55
|
+
spec.add_dependency 'activesupport'
|
39
56
|
# spec.add_dependency 'tty-box', '~> 0.5.0'
|
40
57
|
end
|
metadata
CHANGED
@@ -1,22 +1,42 @@
|
|
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.28
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- David
|
7
|
+
- David Cruwys
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
12
|
-
dependencies:
|
13
|
-
|
11
|
+
date: 2020-11-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: |2
|
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.
|
14
31
|
email:
|
15
32
|
- david@ideasmen.com.au
|
16
33
|
executables: []
|
17
34
|
extensions: []
|
18
|
-
extra_rdoc_files:
|
35
|
+
extra_rdoc_files:
|
36
|
+
- README.md
|
37
|
+
- STORIES.md
|
19
38
|
files:
|
39
|
+
- ".github/workflows/ruby.yml"
|
20
40
|
- ".gitignore"
|
21
41
|
- ".rspec"
|
22
42
|
- ".rubocop.yml"
|
@@ -27,6 +47,7 @@ files:
|
|
27
47
|
- LICENSE.txt
|
28
48
|
- README.md
|
29
49
|
- Rakefile
|
50
|
+
- STORIES.md
|
30
51
|
- bin/console
|
31
52
|
- bin/k
|
32
53
|
- bin/kgitsync
|
@@ -35,13 +56,16 @@ files:
|
|
35
56
|
- hooks/pre-commit
|
36
57
|
- hooks/update-version
|
37
58
|
- lib/peeky.rb
|
59
|
+
- lib/peeky/api.rb
|
38
60
|
- lib/peeky/attr_info.rb
|
39
61
|
- lib/peeky/class_info.rb
|
62
|
+
- lib/peeky/example/yard_sample.rb
|
40
63
|
- lib/peeky/method_info.rb
|
41
64
|
- lib/peeky/parameter_info.rb
|
42
65
|
- lib/peeky/predicates/attr_reader_predicate.rb
|
43
66
|
- lib/peeky/predicates/attr_writer_predicate.rb
|
44
67
|
- lib/peeky/renderer/class_interface_render.rb
|
68
|
+
- lib/peeky/renderer/class_interface_yard_render.rb
|
45
69
|
- lib/peeky/renderer/method_call_minimum_params_render.rb
|
46
70
|
- lib/peeky/renderer/method_signature_render.rb
|
47
71
|
- lib/peeky/renderer/method_signature_with_debug_render.rb
|
@@ -54,8 +78,14 @@ metadata:
|
|
54
78
|
homepage_uri: http://appydave.com/gems/peeky
|
55
79
|
source_code_uri: https://github.com/klueless-io/peeky
|
56
80
|
changelog_uri: https://github.com/klueless-io/peeky/commits/master
|
81
|
+
documentation_uri: https://rubydoc.info/github/klueless-io/peeky/master
|
57
82
|
post_install_message:
|
58
|
-
rdoc_options:
|
83
|
+
rdoc_options:
|
84
|
+
- "--title"
|
85
|
+
- peeky by appydave.com
|
86
|
+
- "--main"
|
87
|
+
- README.md
|
88
|
+
- "--files STORIES.MD"
|
59
89
|
require_paths:
|
60
90
|
- lib
|
61
91
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -72,5 +102,5 @@ requirements: []
|
|
72
102
|
rubygems_version: 3.1.4
|
73
103
|
signing_key:
|
74
104
|
specification_version: 4
|
75
|
-
summary:
|
105
|
+
summary: Take a peek into your ruby classes and extract useful meta data
|
76
106
|
test_files: []
|