peeky 0.0.33 → 0.0.39

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2f39a9477e701fff31e203e1d90fb479cd8898662499edf4c4722673e7c0da20
4
- data.tar.gz: d7a743fc208c5dbfe640c687833e3cc69b663654630cad0d15a582033f3f39f8
3
+ metadata.gz: 3247c282a72d505136e9a837dfc2b834b793234fafac57d34abf01845d3573cb
4
+ data.tar.gz: 7687ce409a954be8b01462f707bb08f8724ed5fee649203a1ddbc3a5d22802d8
5
5
  SHA512:
6
- metadata.gz: dd1a24d91ef1fef5b72fc90f2c041112462cc842009ed68f9499f9a94cc3218ff0e2a0bc46ba4b5564487891b54d2bff023cf4deaa8af64a607f207b4f6a8e6f
7
- data.tar.gz: 8fe132fffb24332d7b28b92a288b799ed51dac71df7bcfb8887bec7c6433c3b58bda9a6af05cb81dc006322b5991b6b05735760756dcef4c8919575e16155bd8
6
+ metadata.gz: 4bdaba25fa466a29378293696530be6f8e7630e45e9d37c77016e0fe09fc5e0712b411a3c70627a21dae7e439c82d66465c09f3b08607534dbb0650ae7dd2185
7
+ data.tar.gz: 32a64cf623e9056e47a66861a541199d6144efdbf2551341cd4d770cce51962f4b3f5c840bda0b1d3c8545476f66c74885d7b530617246a0a4a97dfe3773f3fd
@@ -1,6 +1,5 @@
1
1
  # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
2
2
  # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
3
-
4
3
  name: Ruby
5
4
 
6
5
  on:
@@ -19,10 +18,10 @@ jobs:
19
18
  - name: Set up Ruby
20
19
  # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
21
20
  # change this to (see https://github.com/ruby/setup-ruby#versioning):
22
- # uses: ruby/setup-ruby@v1
23
- uses: ruby/setup-ruby@ec106b438a1ff6ff109590de34ddc62c540232e0
21
+ uses: ruby/setup-ruby@v1
24
22
  with:
25
23
  ruby-version: 2.6
24
+ # bundler-cache: true # runs 'bundle install' and caches installed gems automatically
26
25
  - name: Install dependencies
27
26
  run: bundle install
28
27
  - name: Run tests
data/.rubocop.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  AllCops:
2
+ TargetRubyVersion: 2.5
2
3
  DisplayCopNames: true
3
4
  ExtraDetails: true
4
5
  NewCops: enable
@@ -7,6 +8,8 @@ AllCops:
7
8
  - "lib/peeky/example/yard_sample.rb"
8
9
 
9
10
  # My Preferences - Start
11
+ Metrics/ClassLength:
12
+ Enabled: false
10
13
  Naming/MemoizedInstanceVariableName:
11
14
  Enabled: false
12
15
  Naming/VariableNumber:
@@ -35,9 +38,9 @@ Layout/SpaceBeforeComma:
35
38
 
36
39
  Metrics/BlockLength:
37
40
  Exclude:
38
- - "**/spec/*"
41
+ - "**/spec/**/*"
39
42
  - "*.gemspec"
40
- ExcludedMethods:
43
+ IgnoredMethods:
41
44
  - configure
42
45
  - context
43
46
  - define
data/Gemfile CHANGED
@@ -5,19 +5,25 @@ source 'https://rubygems.org'
5
5
  # Specify your gem's dependencies in poc_github_ap.gemspec
6
6
  gemspec
7
7
 
8
- # group :development do
9
- # # pry on steroids
10
- # gem 'pry-coolline', github: 'owst/pry-coolline', branch: 'support_new_pry_config_api'
11
- # gem 'jazz_fingers'
12
- # end
8
+ group :development do
9
+ # pry on steroids
10
+ # gem 'pry-coolline', github: 'owst/pry-coolline', branch: 'support_new_pry_config_api'
11
+ # gem 'jazz_fingers'
12
+ end
13
13
 
14
14
  group :development, :test do
15
- gem 'guard-bundler'
16
- gem 'guard-rspec'
17
- gem 'guard-rubocop'
15
+ gem 'guard-bundler', '~> 3.0'
16
+ gem 'guard-rspec', '~> 4.0'
17
+ gem 'guard-rubocop', '~> 1.2'
18
18
  gem 'rake', '~> 12.0'
19
19
  # this is used for cmdlets 'self-executing gems'
20
20
  gem 'rake-compiler'
21
21
  gem 'rspec', '~> 3.0'
22
- gem 'rubocop'
22
+ gem 'rubocop', '~> 1.9'
23
+ gem 'rubocop-rake', require: false
24
+ gem 'rubocop-rspec', require: false
23
25
  end
26
+
27
+ # group :test do
28
+ # gem 'k_usecases', path: '~/dev/kgems/k_usecases'
29
+ # end
data/Guardfile CHANGED
@@ -23,8 +23,8 @@ group :green_pass_then_cop, halt_on_fail: true do
23
23
  watch(%r{^lib/peeky/commands/(.+)\.rb$}) { |m| "spec/unit/commands/#{m[1]}_spec.rb" }
24
24
  end
25
25
 
26
- # guard :rubocop, all_on_start: false, cli: ['--format', 'clang'] do
27
- # watch(%r{.+\.rb$})
28
- # watch(%r{(?:.+/)?\.rubocop(?:_todo)?\.yml$}) { |m| File.dirname(m[0]) }
29
- # end
26
+ guard :rubocop, all_on_start: false, cli: ['--format', 'clang'] do
27
+ watch(%r{.+\.rb$})
28
+ watch(%r{(?:.+/)?\.rubocop(?:_todo)?\.yml$}) { |m| File.dirname(m[0]) }
29
+ end
30
30
  end
data/USAGE2.md ADDED
@@ -0,0 +1,5 @@
1
+ # Peeky
2
+
3
+ This document will show you how to use Peeky.
4
+
5
+ Peeky is a Ruby GEM for peaking into ruby classes and extracting meta
data/lib/peeky/api.rb CHANGED
@@ -16,6 +16,9 @@ module Peeky
16
16
  # ClassInfo stores information about the instance of a
17
17
  # class that is passed in including methods, attr_accessors
18
18
  # attr_readers and attr_writers.
19
+ #
20
+ # @param instance [Object] instance of class to gather information about (required)
21
+ # @param lazy [TrueClass] lazy load method and parameter information, laze: is optional, defaults to true
19
22
  def build_class_info(instance, lazy: true)
20
23
  ci = Peeky::ClassInfo.new(instance)
21
24
  ci.load unless lazy
@@ -23,6 +26,14 @@ module Peeky
23
26
  end
24
27
 
25
28
  # Render a class using a predefined class renderer
29
+ #
30
+ # ^1: One of class_info and instance must supplied, they are mutually
31
+ # exclusive to each other.
32
+ #
33
+ # @param render_key [Symbol] class render key (required)
34
+ # @param class_info [Object] class_info: is optional^1, defaults to nil
35
+ # @param instance [Object] instance: is optional^1, defaults to nil
36
+ # @param _opts [<key: value>...] **_opts - list of key/values that can help configure render
26
37
  def render_class(render_key, class_info: nil, instance: nil, **_opts)
27
38
  raise 'Call render_class with class_info OR instance.' if class_info.nil? && instance.nil?
28
39
  raise 'Call render_class with class_info OR instance, these parameters are mutually exclusive' if !class_info.nil? && !instance.nil?
@@ -37,6 +48,7 @@ module Peeky
37
48
  # Get a method renderer by :key
38
49
  #
39
50
  # TODO: Refactor to a configurable system
51
+ # @param key [String] key is a shortcut to a specific Peeky::Render that handles method_info (required)
40
52
  def method_renderer(key)
41
53
  case key
42
54
  when :signature
@@ -53,6 +65,7 @@ module Peeky
53
65
  # Get a class renderer by :key
54
66
  #
55
67
  # TODO: Refactor to a configurable system
68
+ # @param key [String] key is a shortcut to a specific Peeky::Renderer that handles class_info (required)
56
69
  def class_renderer(key)
57
70
  case key
58
71
  when :class_debug
@@ -6,7 +6,9 @@ module Peeky
6
6
  # Attr Info is a container that holds read, write or read/write
7
7
  # attributes in the form of MethodInfo objects
8
8
  class AttrInfo
9
+ # reader stores a MethodInfo for a matching reader, nil if readable style method_info not found
9
10
  attr_reader :reader
11
+ # writer stores a MethodInfo for a matching writer, nil if writable style method_info not found
10
12
  attr_reader :writer
11
13
 
12
14
  def initialize(reader: nil, writer: nil)
@@ -16,6 +18,7 @@ module Peeky
16
18
  @writer = writer
17
19
  end
18
20
 
21
+ # Type of the attribute [:attr_writer, :attr_reader or :attr_accessor]
19
22
  def type
20
23
  @type ||= if @reader.nil?
21
24
  :attr_writer
@@ -24,6 +27,7 @@ module Peeky
24
27
  end
25
28
  end
26
29
 
30
+ # Name of the attribute
27
31
  def name
28
32
  @name ||= @reader.nil? ? @writer.clean_name : @reader.clean_name
29
33
  end
@@ -17,9 +17,29 @@ module Peeky
17
17
  @instance = instance
18
18
  end
19
19
 
20
+ # rubocop:disable Metrics/AbcSize
20
21
  def to_s
21
- class_full_name
22
+ result = []
23
+ result.push kv('class', class_full_name)
24
+ if defined?(@_ruby_instance_method_names)
25
+ result.push kv('# of instance methods', @_ruby_instance_method_names.join(', '))
26
+ else
27
+ result.push kv('# of instance methods', '')
28
+ end
29
+ if defined?(@_signatures)
30
+ result.push kv('# of accessors', accessors.length)
31
+ result.push kv('# of readers', readers.length)
32
+ result.push kv('# of writers', writers.length)
33
+ result.push kv('# of methods', methods.length)
34
+ else
35
+ result.push kv('# of accessors', '')
36
+ result.push kv('# of readers', '')
37
+ result.push kv('# of writers', '')
38
+ result.push kv('# of methods', '')
39
+ end
40
+ result.join("\n")
22
41
  end
42
+ # rubocop:enable Metrics/AbcSize
23
43
 
24
44
  # Load class_info
25
45
  #
@@ -161,34 +181,12 @@ module Peeky
161
181
  signatures.select { |im| im.name == name && im.implementation_type == filter_type }
162
182
  end
163
183
 
164
- # Debug
165
- #
166
- # Refact: PATTERN: Come up it an debug inclusion system so that
167
- # so that debug helpers can be included for development and excluded
168
- # for production
169
- # @param format [String] format: <value for format> (optional)
170
- def debug(format: [:signatures])
171
- debug_method_names if format.include?(:method_names)
172
-
173
- return unless format.include?(:signatures)
174
-
175
- puts '-' * 70
176
- puts 'Methods'
177
- puts '-' * 70
178
- signatures.each(&:debug)
179
- end
180
-
181
- def debug_method_names
182
- puts '-' * 70
183
- puts 'Method Names'
184
- puts '-' * 70
185
- ruby_instance_method_names.each do |method_name|
186
- puts method_name
187
- end
188
- end
189
-
190
184
  private
191
185
 
186
+ def kv(key, value)
187
+ "#{key.to_s.ljust(25)}: #{value}"
188
+ end
189
+
192
190
  def ruby_instance_method_names
193
191
  @_ruby_instance_method_names ||= instance.class.instance_methods(false).sort
194
192
  end
@@ -47,16 +47,16 @@ module Peeky
47
47
  # F method with required param and optional param
48
48
  #
49
49
  # @param first_name [String] first name (required)
50
- # @param last_name [String] last name (optional)
51
- def f_method_with_required_param_and_optional_param(first_name, last_name = nil)
50
+ # @param last_name [String] last_name is optional, defaults to ''
51
+ def f_method_with_required_param_and_optional_param(first_name, last_name = '')
52
52
  end
53
53
 
54
54
  # G method with required param and two optional params
55
55
  #
56
56
  # @param first_name [String] first name (required)
57
- # @param last_name [String] last name (optional)
58
- # @param age [String] age (optional)
59
- def g_method_with_required_param_and_two_optional_params(first_name, last_name = nil, age = nil)
57
+ # @param last_name [String] last_name is optional, defaults to ''
58
+ # @param age [Integer] age is optional, defaults to 21
59
+ def g_method_with_required_param_and_two_optional_params(first_name, last_name = '', age = 21)
60
60
  end
61
61
 
62
62
  # H list of optional parameters
@@ -94,8 +94,8 @@ module Peeky
94
94
  # N method with key value param required and optional key value
95
95
  #
96
96
  # @param last_name [String] last_name: <value for last name> (required)
97
- # @param salutation [String] salutation: <value for salutation> (optional)
98
- def n_method_with_key_value_param_required_and_optional_key_value(last_name:, salutation: nil)
97
+ # @param salutation [String] salutation: is optional, defaults to 'Mr'
98
+ def n_method_with_key_value_param_required_and_optional_key_value(last_name:, salutation: 'Mr')
99
99
  end
100
100
 
101
101
  # P available?
@@ -111,13 +111,29 @@ module Peeky
111
111
  # Z complex
112
112
  #
113
113
  # @param aaa [String] aaa (required)
114
- # @param bbb [String] bbb (optional)
114
+ # @param bbb [Integer] bbb is optional, defaults to 1
115
115
  # @param ccc [Array<Object>] *ccc - list of ccc
116
116
  # @param ddd [String] ddd: <value for ddd> (required)
117
- # @param eee [String] eee: <value for eee> (optional)
117
+ # @param eee [Integer] eee: is optional, defaults to 1
118
118
  # @param fff [<key: value>...] **fff - list of key/values
119
119
  # @param ggg [Block] &ggg
120
- def z_complex(aaa, bbb = nil, *ccc, ddd:, eee: nil, **fff, &ggg)
120
+ def z_complex(aaa, bbb = 1, *ccc, ddd:, eee: 1, **fff, &ggg)
121
+ end
122
+
123
+ # Z optional styles
124
+ #
125
+ # @param aaa [String] aaa (required)
126
+ # @param bbb [Integer] bbb is optional, defaults to 123
127
+ # @param ccc [String] ccc is optional, defaults to 'abc'
128
+ # @param ddd [TrueClass] ddd is optional, defaults to true
129
+ # @param eee [FalseClass] eee is optional, defaults to false
130
+ # @param fff [Object] fff is optional, defaults to nil
131
+ # @param ggg [Integer] ggg: is optional, defaults to 123
132
+ # @param hhh [String] hhh: is optional, defaults to 'xyz'
133
+ # @param iii [TrueClass] iii: is optional, defaults to true
134
+ # @param jjj [FalseClass] jjj: is optional, defaults to false
135
+ # @param kkk [Object] kkk: is optional, defaults to nil
136
+ def z_optional_styles(aaa, bbb = 123, ccc = 'abc', ddd = true, eee = false, fff = nil, ggg: 123, hhh: 'xyz', iii: true, jjj: false, kkk: )
121
137
  end
122
138
  end
123
139
  end
@@ -16,26 +16,35 @@ module Peeky
16
16
 
17
17
  def_delegators :focal_method, :name, :receiver, :arity, :super_method
18
18
 
19
- # Stage 2 is the method likely to be an attribute reader or writer
19
+ ## Stage 2 is the method likely to be an attribute reader or writer
20
+ #
20
21
 
21
22
  # Implementation type indicates the probable representation of this
22
23
  # method in ruby, was it `def method` or `attr_reader` / `attr_writer`
23
24
  attr_reader :implementation_type
24
25
 
25
- # TODO: target_instance is required...
26
- def initialize(method, target_instance = nil)
26
+ def initialize(method, target_instance)
27
27
  @focal_method = method
28
+ @target_instance = target_instance
28
29
  @parameters = ParameterInfo.from_method(method)
29
30
  # stage 1
30
31
  # @implementation_type = :method
31
32
 
32
33
  # stage 2
33
- @implementation_type = infer_implementation_type(target_instance)
34
+ infer_implementation_type
35
+
36
+ # stage 3
37
+ infer_default_paramaters
34
38
  end
35
39
 
36
40
  # Stage 2 (working out) attr_accessor
41
+ #
42
+
37
43
  # Name of method minus writer annotations
38
- # Example :writable_attribute= becomes :writable_attribute
44
+ # Example
45
+ # :writable_attribute=
46
+ # # becomes
47
+ # :writable_attribute
39
48
  def clean_name
40
49
  @clean_name ||= begin
41
50
  n = name.to_s
@@ -43,43 +52,113 @@ module Peeky
43
52
  end
44
53
  end
45
54
 
46
- def infer_implementation_type(target_instance)
47
- if target_instance.nil?
48
- :method
49
- elsif match(target_instance, Peeky::Predicates::AttrReaderPredicate)
50
- :attr_reader
51
- elsif match(target_instance, Peeky::Predicates::AttrWriterPredicate)
52
- :attr_writer
53
- else
54
- :method
55
+ # Infer implementation type [:method, :attr_reader or :attr_writer]
56
+ # rubocop:disable Lint/DuplicateBranch
57
+ def infer_implementation_type
58
+ @implementation_type = if @target_instance.nil?
59
+ :method
60
+ elsif match(Peeky::Predicates::AttrReaderPredicate)
61
+ :attr_reader
62
+ elsif match(Peeky::Predicates::AttrWriterPredicate)
63
+ :attr_writer
64
+ else
65
+ :method
66
+ end
67
+ end
68
+ # rubocop:enable Lint/DuplicateBranch
69
+
70
+ # Get parameter by name
71
+ #
72
+ # @param name [String] name (required)
73
+ def get_parameter(name)
74
+ name = name.to_s
75
+ parameters.find { |p| p.name == name }
76
+ end
77
+
78
+ # Has any optional paramaters?
79
+
80
+ # @return [Boolean] true when any parameter is optional?
81
+ def optional?
82
+ parameters.any?(&:optional?)
83
+ end
84
+
85
+ # Infer default paramater values
86
+ #
87
+ # WARNING: Unit test coverage went from .1 seconds to 30-40 seconds
88
+ # when I first introduced this method.
89
+ #
90
+ # I now only call TracePoint if I have optional parameters to be inferred.
91
+ #
92
+ # The tests are now down to 5 seconds, but it highlights the cost of use
93
+ # TracePoint.
94
+ def infer_default_paramaters
95
+ minimalist_method = Peeky::Renderer::MethodCallMinimumParamsRender.new(self).render
96
+
97
+ return if minimalist_method.end_with?('=')
98
+ return unless optional?
99
+
100
+ tracer.enable do
101
+ @target_instance.instance_eval(minimalist_method)
102
+ rescue StandardError => e
103
+ # just print the error for now, we are only attempting to capture the
104
+ # first call, any errors inside the call cannot be dealt with and should
105
+ # not be re-raised
106
+ puts e.message
107
+ end
108
+ end
109
+
110
+ def tracer
111
+ TracePoint.trace(:call, :c_call) do |tp|
112
+ next unless tp.self.is_a?(@target_instance.class)
113
+ next unless tp.method_id == name
114
+
115
+ tp.parameters.each do |_type, param_name|
116
+ method_paramater = get_parameter(param_name)
117
+
118
+ if method_paramater.optional?
119
+ value = tp.binding.local_variable_get(param_name)
120
+ method_paramater.default_value = value
121
+ end
122
+ end
55
123
  end
56
124
  end
57
125
 
58
- def match(target_instance, predicate)
59
- predicate.new.match(target_instance, self)
126
+ # Match
127
+ #
128
+ # @param predicate [String] use a predicate object with the signature match(instance, method_info)
129
+ def match(predicate)
130
+ predicate.new.match(@target_instance, self)
60
131
  end
61
132
 
133
+ # Method?
134
+
135
+ # @return [Boolean] true when implementation type is method?
62
136
  def method?
63
137
  @implementation_type == :method
64
138
  end
65
139
 
66
- # https://github.com/rubyide/vscode-ruby/issues/454
67
- # if I prefix these methods with attr_ then will get an issue
68
- # in the language server.
69
- # Cannot read property 'namedChildren' of undefined
140
+ # Readable?
141
+ #
142
+ # @return [Boolean] true when readable?
70
143
  def readable?
144
+ # Method naming issue: VSCode Ruby Language Server
145
+ #
146
+ # If this method is renamed to attr_readable, same for attr_writable.
147
+ #
148
+ # https://github.com/rubyide/vscode-ruby/issues/454
149
+ # if I prefix these methods with attr_ then will get an issue
150
+ # in the language server.
151
+ #
152
+ # Cannot read property 'namedChildren' of undefined
153
+
71
154
  @implementation_type == :attr_reader
72
155
  end
73
156
 
157
+ # Writable?
158
+
159
+ # @return [Boolean] true when implementation_type writable?
74
160
  def writable?
75
161
  @implementation_type == :attr_writer
76
162
  end
77
-
78
- def debug
79
- puts '-' * 70
80
- puts name
81
- puts '-' * 70
82
- parameters.each(&:debug)
83
- end
84
163
  end
85
164
  end
@@ -48,13 +48,6 @@ module Peeky
48
48
  ruby_method.parameters.map { |ruby_paramater| from_parameter(ruby_paramater) }
49
49
  end
50
50
 
51
- def debug
52
- puts "name : #{name}"
53
- puts "type : #{type}"
54
- puts "signature_format : #{signature_format}"
55
- puts "minimal_call_format : #{minimal_call_format}"
56
- end
57
-
58
51
  # ruby code formatted for use in a method signature
59
52
  def signature_format
60
53
  @_signature_format ||= begin
@@ -79,6 +72,34 @@ module Peeky
79
72
  end
80
73
  end
81
74
 
75
+ # Optional?
76
+
77
+ # @return [Boolean] true when parameter is one of the optional types?
78
+ def optional?
79
+ @_optional |= (@type == :param_optional || @type == :key_optional)
80
+ end
81
+
82
+ # Default value type will look at the default value and try to
83
+ # infer the class behind it. Will default to 'Object' fi nil
84
+ def default_value_type
85
+ if @default_value.nil?
86
+ 'Object'
87
+ else
88
+ @default_value.class
89
+ end
90
+ end
91
+
92
+ # Wrap default value in quotes if string, or no wrapping otherwise
93
+ #
94
+ # @param value_for_nil [String] value for nil, generally '' or 'nil' (required)
95
+ def wrap_default_value(value_for_nil)
96
+ if @default_value.is_a?(String)
97
+ "'#{@default_value}'"
98
+ else
99
+ @default_value.nil? ? value_for_nil : @default_value
100
+ end
101
+ end
102
+
82
103
  private
83
104
 
84
105
  # Convert the limited information provided by ruby method.parameters
@@ -118,7 +139,7 @@ module Peeky
118
139
  end
119
140
 
120
141
  def signature_format_param_optional
121
- "#{name} = nil" # signature format needs to be moved to a method
142
+ "#{name} = #{wrap_default_value('nil')}" # signature format needs to be moved to a method
122
143
  end
123
144
 
124
145
  def signature_format_splat
@@ -130,7 +151,7 @@ module Peeky
130
151
  end
131
152
 
132
153
  def signature_format_key_optional
133
- "#{name}: nil"
154
+ "#{name}: #{wrap_default_value('')}"
134
155
  end
135
156
 
136
157
  def signature_format_double_splat
@@ -152,28 +173,8 @@ module Peeky
152
173
  "'#{@name}'"
153
174
  end
154
175
 
155
- # def minimal_call_format_param_optional
156
- # ''
157
- # end
158
-
159
- # def minimal_call_format_splat
160
- # ''
161
- # end
162
-
163
176
  def minimal_call_format_key_required
164
177
  "#{@name}: '#{@name}'"
165
178
  end
166
-
167
- # def minimal_call_format_key_optional
168
- # ''
169
- # end
170
-
171
- # def minimal_call_format_double_splat
172
- # ''
173
- # end
174
-
175
- # def minimal_call_format_block
176
- # ''
177
- # end
178
179
  end
179
180
  end
@@ -19,7 +19,7 @@ module Peeky
19
19
  attributes = render_accessors + render_readers + render_writers
20
20
 
21
21
  if attributes.length.positive?
22
- output.push("-- Attributes #{'-' * 56}")
22
+ output.push("-- Attributes #{'-' * 86}")
23
23
  output.push(*attributes)
24
24
  output.push('')
25
25
  end
@@ -27,7 +27,7 @@ module Peeky
27
27
  methods = render_methods
28
28
 
29
29
  if methods.length.positive?
30
- output.push("-- Public Methods #{'-' * 52}")
30
+ output.push("-- Public Methods #{'-' * 82}")
31
31
  output.push(*methods)
32
32
  output.push('')
33
33
  end
@@ -40,7 +40,7 @@ module Peeky
40
40
 
41
41
  private
42
42
 
43
- def lj(value, size = 20)
43
+ def lj(value, size = 24)
44
44
  value.to_s.ljust(size)
45
45
  end
46
46
 
@@ -50,7 +50,7 @@ module Peeky
50
50
 
51
51
  def class_details
52
52
  [
53
- '-' * 70,
53
+ '-' * 100,
54
54
  kv('class name', @class_info.class_name),
55
55
  kv('module name', @class_info.module_name),
56
56
  kv('class full name', @class_info.class_full_name),
@@ -82,12 +82,12 @@ module Peeky
82
82
 
83
83
  def render_paramaters(parameters)
84
84
  result = [
85
- "#{lj('name')} #{lj('param format')} #{lj('type')}",
86
- '-' * 70
85
+ "#{lj('name')} #{lj('param format')} #{lj('type')} #{lj('default')}",
86
+ '-' * 100
87
87
  ]
88
88
 
89
89
  result + parameters.map do |param|
90
- "#{lj(param.name)} #{lj(param.signature_format)} #{lj(param.type)}"
90
+ "#{lj(param.name)} #{lj(param.signature_format)} #{lj(param.type)} #{lj(param.default_value)}"
91
91
  end
92
92
  end
93
93
  end
@@ -108,11 +108,12 @@ module Peeky
108
108
  when :key_required
109
109
  result.push "#{@indent}# @param #{parameter.name} [#{default_param_type}] #{parameter.name}: <value for #{parameter.name.to_s.humanize.downcase}> (required)"
110
110
  when :key_optional
111
- result.push "#{@indent}# @param #{parameter.name} [#{default_param_type}] #{parameter.name}: <value for #{parameter.name.to_s.humanize.downcase}> (optional)"
111
+ result.push "#{@indent}# @param #{parameter.name} [#{parameter.default_value_type}] #{parameter.name}: is optional, defaults to #{parameter.wrap_default_value('nil')}"
112
112
  when :param_required
113
113
  result.push "#{@indent}# @param #{parameter.name} [#{default_param_type}] #{parameter.name.to_s.humanize.downcase} (required)"
114
114
  when :param_optional
115
- result.push "#{@indent}# @param #{parameter.name} [#{default_param_type}] #{parameter.name.to_s.humanize.downcase} (optional)"
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)"
116
117
  else
117
118
  result.push "#{@indent}# @param #{parameter.name} [#{default_param_type}] #{parameter.name.to_s.humanize.downcase}"
118
119
  end
@@ -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
- "#{@instance_name}.#{name}#{params}"
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Peeky
4
- VERSION = '0.0.33'
4
+ VERSION = '0.0.39'
5
5
  end
data/peeky.gemspec CHANGED
@@ -3,49 +3,34 @@
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/
7
- spec.required_ruby_version = '>= 2.5'
8
6
  spec.name = 'peeky'
9
7
  spec.version = Peeky::VERSION
10
8
  spec.authors = ['David Cruwys']
11
9
  spec.email = ['david@ideasmen.com.au']
12
10
 
13
11
  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
-
12
+ spec.description = 'peeky'
20
13
  spec.homepage = 'http://appydave.com/gems/peeky'
21
14
  spec.license = 'MIT'
22
-
23
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
24
- # to allow pushing to a single host or delete this section to allow pushing to any host.
25
- 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')
26
16
 
27
17
  # spec.metadata['allowed_push_host'] = "Set to 'http://mygemserver.com'"
28
18
 
29
19
  spec.metadata['homepage_uri'] = spec.homepage
30
20
  spec.metadata['source_code_uri'] = 'https://github.com/klueless-io/peeky'
31
21
  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'
36
22
 
37
23
  # Specify which files should be added to the gem when it is released.
38
24
  # The `git ls-files -z` loads the RubyGem files that have been added into git.
39
25
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
40
- `git ls-files -z`.split("\x0").reject do |f|
41
- f.match(%r{^(test|spec|features)/})
42
- end
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
43
27
  end
44
28
  spec.bindir = 'exe'
45
29
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
46
30
  spec.require_paths = ['lib']
31
+
47
32
  # spec.extensions = ['ext/peeky/extconf.rb']
48
- spec.extra_rdoc_files = ['README.md', 'STORIES.md']
33
+ spec.extra_rdoc_files = ['README.md', 'STORIES.md', 'USAGE.md']
49
34
  spec.rdoc_options += [
50
35
  '--title', 'peeky by appydave.com',
51
36
  '--main', 'README.md',
@@ -53,5 +38,4 @@ Gem::Specification.new do |spec|
53
38
  ]
54
39
 
55
40
  spec.add_dependency 'activesupport'
56
- # spec.add_dependency 'tty-box', '~> 0.5.0'
57
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.33
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: 2020-11-08 00:00:00.000000000 Z
11
+ date: 2021-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -24,10 +24,7 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
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.
27
+ description: peeky
31
28
  email:
32
29
  - david@ideasmen.com.au
33
30
  executables: []
@@ -35,6 +32,7 @@ extensions: []
35
32
  extra_rdoc_files:
36
33
  - README.md
37
34
  - STORIES.md
35
+ - USAGE.md
38
36
  files:
39
37
  - ".github/workflows/ruby.yml"
40
38
  - ".gitignore"
@@ -49,6 +47,7 @@ files:
49
47
  - Rakefile
50
48
  - STORIES.md
51
49
  - USAGE.md
50
+ - USAGE2.md
52
51
  - bin/console
53
52
  - bin/k
54
53
  - bin/kgitsync
@@ -80,7 +79,6 @@ metadata:
80
79
  homepage_uri: http://appydave.com/gems/peeky
81
80
  source_code_uri: https://github.com/klueless-io/peeky
82
81
  changelog_uri: https://github.com/klueless-io/peeky/commits/master
83
- documentation_uri: https://rubydoc.info/github/klueless-io/peeky/master
84
82
  post_install_message:
85
83
  rdoc_options:
86
84
  - "--title"
@@ -94,14 +92,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
94
92
  requirements:
95
93
  - - ">="
96
94
  - !ruby/object:Gem::Version
97
- version: '2.5'
95
+ version: 2.4.0
98
96
  required_rubygems_version: !ruby/object:Gem::Requirement
99
97
  requirements:
100
98
  - - ">="
101
99
  - !ruby/object:Gem::Version
102
100
  version: '0'
103
101
  requirements: []
104
- rubygems_version: 3.1.4
102
+ rubygems_version: 3.2.7
105
103
  signing_key:
106
104
  specification_version: 4
107
105
  summary: Take a peek into your ruby classes and extract useful meta data