peeky 0.0.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +46 -0
- data/.rspec +3 -0
- data/.rubocop.yml +57 -0
- data/.rubocop_todo.yml +54 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +20 -0
- data/Guardfile +30 -0
- data/LICENSE.txt +21 -0
- data/README.md +85 -0
- data/Rakefile +16 -0
- data/bin/console +16 -0
- data/bin/k +36 -0
- data/bin/kgitsync +76 -0
- data/bin/khotfix +244 -0
- data/bin/setup +11 -0
- data/hooks/pre-commit +87 -0
- data/hooks/update-version +21 -0
- data/lib/peeky.rb +21 -0
- data/lib/peeky/attr_info.rb +63 -0
- data/lib/peeky/class_info.rb +92 -0
- data/lib/peeky/method_info.rb +83 -0
- data/lib/peeky/parameter_info.rb +104 -0
- data/lib/peeky/predicates/attr_reader_predicate.rb +39 -0
- data/lib/peeky/predicates/attr_writer_predicate.rb +29 -0
- data/lib/peeky/renderer/class_interface_render.rb +96 -0
- data/lib/peeky/renderer/method_call_minimum_params_render.rb +37 -0
- data/lib/peeky/renderer/method_signature_render.rb +39 -0
- data/lib/peeky/renderer/method_signature_with_debug_render.rb +86 -0
- data/lib/peeky/version.rb +5 -0
- data/peeky.gemspec +40 -0
- metadata +76 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Peeky
|
4
|
+
module Renderer
|
5
|
+
# Render: Simple instance method calls with minimum parameters
|
6
|
+
#
|
7
|
+
# Example output:
|
8
|
+
# instance.simple('first_param')
|
9
|
+
# instance.complex('aaa', ddd: 'ddd')
|
10
|
+
class MethodCallMinimumParamsRender
|
11
|
+
attr_reader :method_signature
|
12
|
+
|
13
|
+
def initialize(method_signature, instance_name = 'instance')
|
14
|
+
@instance_name = instance_name
|
15
|
+
@method_signature = method_signature
|
16
|
+
end
|
17
|
+
|
18
|
+
def render
|
19
|
+
name = method_signature.name
|
20
|
+
|
21
|
+
minimal_call_parameters = method_signature
|
22
|
+
.parameters
|
23
|
+
.map(&:minimal_call_format)
|
24
|
+
.reject { |minimal_call| minimal_call.nil? || minimal_call.strip.empty? }
|
25
|
+
.join(', ')
|
26
|
+
|
27
|
+
params = minimal_call_parameters.length.zero? ? '' : "(#{minimal_call_parameters})"
|
28
|
+
|
29
|
+
"#{@instance_name}.#{name}#{params}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def debug
|
33
|
+
puts render
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Peeky
|
4
|
+
module Renderer
|
5
|
+
# Render: Method Signature in compact format
|
6
|
+
#
|
7
|
+
# Example output:
|
8
|
+
# def simple(first_param); end
|
9
|
+
# def complex(aaa, bbb = nil, *ccc, ddd:, eee: nil, **fff, &ggg); end
|
10
|
+
class MethodSignatureRender
|
11
|
+
attr_reader :method_signature
|
12
|
+
|
13
|
+
def initialize(method_signature)
|
14
|
+
@method_signature = method_signature
|
15
|
+
end
|
16
|
+
|
17
|
+
def render_signature
|
18
|
+
name = method_signature.name
|
19
|
+
|
20
|
+
formatted_parameters = method_signature.parameters.map(&:signature_format).join(', ')
|
21
|
+
params = formatted_parameters.length.zero? ? '' : "(#{formatted_parameters})"
|
22
|
+
"def #{name}#{params}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def render_end
|
26
|
+
'end'
|
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
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Peeky
|
4
|
+
module Renderer
|
5
|
+
# Render: Method signature with debug code
|
6
|
+
# Stubbed Method Render
|
7
|
+
#
|
8
|
+
# Example output:
|
9
|
+
# def simple(first_param)
|
10
|
+
# puts 'method name: simple'
|
11
|
+
# puts first_param # first_param is a required positional paramater
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# def complex(aaa, bbb = nil, *ccc, ddd:, eee: nil, **fff, &ggg)
|
15
|
+
# puts 'method name: complex'
|
16
|
+
# puts aaa # aaa is a required positional paramater
|
17
|
+
# puts bbb # bbb is an optional positional paramater
|
18
|
+
# puts ccc # *ccc takes a list of positional params
|
19
|
+
# puts ddd # ddd: is a required named parameter
|
20
|
+
# puts eee # eee: is an optional named parameter
|
21
|
+
# puts fff # **fff takes a list of optional named parameters
|
22
|
+
# puts ggg # &ggg is block with many calling options, example - instance_eval(&block) if block_given?
|
23
|
+
# end
|
24
|
+
class MethodSignatureWithDebugRender
|
25
|
+
attr_reader :method_signature
|
26
|
+
|
27
|
+
def initialize(method_signature)
|
28
|
+
@method_signature = method_signature
|
29
|
+
|
30
|
+
@render_signature = Peeky::Renderer::MethodSignatureRender.new(method_signature)
|
31
|
+
end
|
32
|
+
|
33
|
+
def render_method
|
34
|
+
name = method_signature.name
|
35
|
+
|
36
|
+
indent = ''
|
37
|
+
output = "#{indent}#{@render_signature.render_signature}\n"
|
38
|
+
indent = ' '
|
39
|
+
output += "#{indent}puts 'method name: #{name}'\n"
|
40
|
+
|
41
|
+
output += render_logic(indent, 30)
|
42
|
+
|
43
|
+
indent = ''
|
44
|
+
output += "#{indent}#{@render_signature.render_end}\n"
|
45
|
+
|
46
|
+
output
|
47
|
+
end
|
48
|
+
|
49
|
+
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
50
|
+
def render_logic(indent, size)
|
51
|
+
output = ''
|
52
|
+
method_signature.parameters.each do |parameter|
|
53
|
+
line = ''
|
54
|
+
case parameter.type
|
55
|
+
when :param_required
|
56
|
+
line = "puts #{parameter.name.ljust(size)} # #{parameter.name} is a required positional paramater"
|
57
|
+
when :param_optional
|
58
|
+
line = "puts #{parameter.name.ljust(size)} # #{parameter.name} is an optional positional paramater"
|
59
|
+
when :splat
|
60
|
+
line = "puts #{parameter.name.ljust(size)} # *#{parameter.name} takes a list of positional params"
|
61
|
+
when :key_required
|
62
|
+
line = "puts #{parameter.name.ljust(size)} # #{parameter.name}: is a required named parameter"
|
63
|
+
when :key_optional
|
64
|
+
line = "puts #{parameter.name.ljust(size)} # #{parameter.name}: is an optional named parameter"
|
65
|
+
when :double_splat
|
66
|
+
line = "puts #{parameter.name.ljust(size)} # **#{parameter.name} takes a list of optional named parameters"
|
67
|
+
when :block
|
68
|
+
line = "puts #{parameter.name.ljust(size)} # &#{parameter.name} is block with many calling options, example - instance_eval(&block) if block_given?"
|
69
|
+
end
|
70
|
+
|
71
|
+
output += "#{indent}#{line}\n"
|
72
|
+
end
|
73
|
+
output
|
74
|
+
end
|
75
|
+
# 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
|
+
end
|
85
|
+
end
|
86
|
+
end
|
data/peeky.gemspec
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/peeky/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.required_ruby_version = '>= 2.5'
|
7
|
+
spec.name = 'peeky'
|
8
|
+
spec.version = Peeky::VERSION
|
9
|
+
spec.authors = ['David']
|
10
|
+
spec.email = ['david@ideasmen.com.au']
|
11
|
+
|
12
|
+
spec.summary = 'Extracting meta data from ruby classes'
|
13
|
+
spec.description = 'Peeky is a Ruby GEM for peaking into ruby classes and extracting meta'
|
14
|
+
spec.homepage = 'http://appydave.com/gems/peeky'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.' unless spec.respond_to?(:metadata)
|
20
|
+
|
21
|
+
# spec.metadata['allowed_push_host'] = "Set to 'http://mygemserver.com'"
|
22
|
+
|
23
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
24
|
+
spec.metadata['source_code_uri'] = 'https://github.com/klueless-io/peeky'
|
25
|
+
spec.metadata['changelog_uri'] = 'https://github.com/klueless-io/peeky/commits/master'
|
26
|
+
|
27
|
+
# Specify which files should be added to the gem when it is released.
|
28
|
+
# The `git ls-files -z` loads the RubyGem files that have been added into git.
|
29
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
30
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
31
|
+
f.match(%r{^(test|spec|features)/})
|
32
|
+
end
|
33
|
+
end
|
34
|
+
spec.bindir = 'exe'
|
35
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
36
|
+
spec.require_paths = ['lib']
|
37
|
+
# spec.extensions = ['ext/peeky/extconf.rb']
|
38
|
+
|
39
|
+
# spec.add_dependency 'tty-box', '~> 0.5.0'
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: peeky
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.14
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-11-03 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Peeky is a Ruby GEM for peaking into ruby classes and extracting meta
|
14
|
+
email:
|
15
|
+
- david@ideasmen.com.au
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- ".rspec"
|
22
|
+
- ".rubocop.yml"
|
23
|
+
- ".rubocop_todo.yml"
|
24
|
+
- CODE_OF_CONDUCT.md
|
25
|
+
- Gemfile
|
26
|
+
- Guardfile
|
27
|
+
- LICENSE.txt
|
28
|
+
- README.md
|
29
|
+
- Rakefile
|
30
|
+
- bin/console
|
31
|
+
- bin/k
|
32
|
+
- bin/kgitsync
|
33
|
+
- bin/khotfix
|
34
|
+
- bin/setup
|
35
|
+
- hooks/pre-commit
|
36
|
+
- hooks/update-version
|
37
|
+
- lib/peeky.rb
|
38
|
+
- lib/peeky/attr_info.rb
|
39
|
+
- lib/peeky/class_info.rb
|
40
|
+
- lib/peeky/method_info.rb
|
41
|
+
- lib/peeky/parameter_info.rb
|
42
|
+
- lib/peeky/predicates/attr_reader_predicate.rb
|
43
|
+
- lib/peeky/predicates/attr_writer_predicate.rb
|
44
|
+
- lib/peeky/renderer/class_interface_render.rb
|
45
|
+
- lib/peeky/renderer/method_call_minimum_params_render.rb
|
46
|
+
- lib/peeky/renderer/method_signature_render.rb
|
47
|
+
- lib/peeky/renderer/method_signature_with_debug_render.rb
|
48
|
+
- lib/peeky/version.rb
|
49
|
+
- peeky.gemspec
|
50
|
+
homepage: http://appydave.com/gems/peeky
|
51
|
+
licenses:
|
52
|
+
- MIT
|
53
|
+
metadata:
|
54
|
+
homepage_uri: http://appydave.com/gems/peeky
|
55
|
+
source_code_uri: https://github.com/klueless-io/peeky
|
56
|
+
changelog_uri: https://github.com/klueless-io/peeky/commits/master
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '2.5'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubygems_version: 3.1.4
|
73
|
+
signing_key:
|
74
|
+
specification_version: 4
|
75
|
+
summary: Extracting meta data from ruby classes
|
76
|
+
test_files: []
|