gelauto 2.0.0 → 2.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a9a90485262d6867a89f54f088f6cd71cd7490b41d22622edd4376387d97555a
4
- data.tar.gz: 808a3f83fd11126ccf4d41ff65e770e28ba9e4d4912bfd9ddca50655471369b9
3
+ metadata.gz: b432e7c9cde4f686b0f5dfe56b1e535c8cbec893552ca72e3881de7c7736d189
4
+ data.tar.gz: 18e9c1edbf6fbdbe624c8e05153250aa1f7d2581d91f8131fc9c6bbbfeb52886
5
5
  SHA512:
6
- metadata.gz: 861d47eebcf4b9709d3cdafa5119a39a30bcecdb0a5fe201accf46464861676a23392322e962afbdd356332537a5fca1bf50e8578baafa7e728564b5d2f9ce6c
7
- data.tar.gz: 19011ece03802f5bd64991382d5cf0b7eae12cc8e431c13ff72e4d807d16a29e949e2a1df90b8505ac1c9f145f731d45af5265686fe3cf27f66699431ce803f8
6
+ metadata.gz: e9a6c22c6d79c023f3e03af57fe46af222379217527cfcb115d2aa10d946052f5f5d635ae9557093bfa2d9281958be1270291fae02b3983e9c7da2c35a2d0228
7
+ data.tar.gz: 6fe764a27342f40aea149cc01a2e92d93ddc9eb79d6e8d343c6685e64d28145a76cb42db2e3f1da60a7e00d54d1eeafecf299062327006f57d1d5ed4c1fbaefc
data/Gemfile CHANGED
@@ -2,6 +2,8 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
+ gem 'sorbet-runtime'
6
+
5
7
  group :development do
6
8
  gem 'pry-byebug'
7
9
  gem 'rspec'
@@ -1,9 +1,10 @@
1
1
  module Gelauto
2
2
  class MethodIndex
3
- attr_reader :index
3
+ attr_reader :index, :sig_index
4
4
 
5
5
  def initialize
6
6
  @index = Hash.new { |h, k| h[k] = {} }
7
+ @sig_index = Hash.new { |h, k| h[k] = {} }
7
8
  end
8
9
 
9
10
  def index_methods_in(path, ast, nesting = [])
@@ -31,6 +32,10 @@ module Gelauto
31
32
  when :class, :module
32
33
  const_name = ast.children.first.children.last
33
34
  return visit_children(path, ast, nesting + [Namespace.new(const_name, ast.type)])
35
+ when :block
36
+ if ast.children.first.children.last == :sig
37
+ sig_index[path][ast.location.line] = true
38
+ end
34
39
  end
35
40
 
36
41
  visit_children(path, ast, nesting)
@@ -66,13 +71,14 @@ module Gelauto
66
71
  def annotate(path, code)
67
72
  lines = code.split(/\r?\n/)
68
73
  mds = index[path]
74
+ sigs = sig_index[path]
69
75
 
70
76
  [].tap do |annotated|
71
77
  lines.each_with_index do |line, idx|
72
78
  lineno = idx + 1
73
79
  md = mds[lineno]
74
80
 
75
- if md.is_a?(MethodDef)
81
+ if md.is_a?(MethodDef) && !sigs[idx]
76
82
  indent = line[0...line.index(/[^\s]/)]
77
83
  annotated << "#{indent}#{md.to_sig}"
78
84
  end
@@ -1,3 +1,3 @@
1
1
  module Gelauto
2
- VERSION = '2.0.0'
2
+ VERSION = '2.1.0'
3
3
  end
@@ -80,6 +80,27 @@ describe Gelauto do
80
80
  end
81
81
  end
82
82
 
83
+ context 'with existing signatures' do
84
+ before do
85
+ Gelauto.discover do
86
+ @request = GelautoSpecs::Request.new
87
+ @request.to_a('Hello', 'World')
88
+ @request.to_s(100)
89
+ end
90
+ end
91
+
92
+ it 'skips existing sig, adds missing sig' do
93
+ file = File.read('spec/support/annotated.rb')
94
+ expect(file.lines.count).to eq(17)
95
+ # does not add a signature to the method with an existing signature
96
+ annotated = annotate(@request, :to_a, file)
97
+ expect(annotated.lines.count).to eq(17)
98
+ # does add a signature to the method without a signature
99
+ annotated = annotate(@request, :to_s, file)
100
+ expect(annotated.lines.count).to eq(18)
101
+ end
102
+ end
103
+
83
104
  context 'with nested generic types' do
84
105
  before do
85
106
  Gelauto.discover do
@@ -20,6 +20,11 @@ RSpec.configure do |config|
20
20
  path, lineno = obj.method(method_name).source_location
21
21
  Gelauto.method_index.find(path, lineno)
22
22
  end
23
+
24
+ def annotate(obj, method_name, code)
25
+ path, _lineno = obj.method(method_name).source_location
26
+ Gelauto.method_index.annotate(path, code)
27
+ end
23
28
  end
24
29
  )
25
30
  end
@@ -0,0 +1,17 @@
1
+ require 'sorbet-runtime'
2
+
3
+ module GelautoSpecs
4
+ class Request
5
+ extend T::Sig
6
+ sig { params(status: String, body: String).returns(T::Array[String]) }
7
+ def to_a(status, body)
8
+ [status, body]
9
+ end
10
+
11
+ def to_s(number)
12
+ number&.to_s
13
+ end
14
+ end
15
+ end
16
+
17
+ Gelauto.paths << __FILE__
@@ -1,3 +1,5 @@
1
+ require 'sorbet-runtime'
2
+
1
3
  module GelautoSpecs
2
4
  class Response
3
5
  attr_reader :status, :body
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gelauto
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Dutro
@@ -72,6 +72,7 @@ files:
72
72
  - lib/gelauto/version.rb
73
73
  - spec/gelauto_spec.rb
74
74
  - spec/spec_helper.rb
75
+ - spec/support/annotated.rb
75
76
  - spec/support/client.rb
76
77
  - spec/support/config.yml
77
78
  - spec/support/image.rb