tapioca 0.14.4 → 0.15.0

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: 6f75efebcf13cb6839056d8869fe4d2d6e2051605a90edf517904d8a14a33913
4
- data.tar.gz: 41fcfa1d3da8c919577146cbbc6a92ad07a62b9e7ac077642ac78290ffb2ecc2
3
+ metadata.gz: f93b130a7096e0712ccd91b8406d92ce537287afafc8aad7586e7f670d88a131
4
+ data.tar.gz: b2cc1e6d2658002600c1edd9c5c88b22704e3f4170ff19aff93bb9fc21df688e
5
5
  SHA512:
6
- metadata.gz: ea78667fe6cf4f54a0b4dd004de2ab465548a231aa2b35d52de83d89e43a0cbd0b21989e249c90415f41dfb5ac8c5082b9a84575bc4eed83418eab9a4a4f33b1
7
- data.tar.gz: 05ea62993f5983a3fb69285f13a07678ddc912e5b7aa5657e81e02906747ab19f17d63a26141deb764d217827ba8097643e3797acf98c31f2323390a52780659
6
+ metadata.gz: aa10ff7ffd4768cea802b63dc68273fa0abf7f69b61a83b1325669e97d706cb8afcc704093c93596a830662fe04b01ad2ded3c166abd69a5c69097bd28f586c9
7
+ data.tar.gz: 63499428de9374990372beb46ece3f98d0f446ba28ef02bfa181179113e37e587ff9867bbe0d729d67c03ddb2813943f6f04d14f2065589a603a766a06ce8096
@@ -46,22 +46,22 @@ module Tapioca
46
46
  GitAttributes.create_vendored_attribute_file(@outpath)
47
47
  end
48
48
 
49
- sig { returns(T::Array[String]) }
49
+ sig { returns(T::Array[GemInfo]) }
50
50
  def list_gemfile_gems
51
51
  say("Listing gems from Gemfile.lock... ", [:blue, :bold])
52
52
  gemfile = Bundler.read_file("Gemfile.lock")
53
53
  parser = Bundler::LockfileParser.new(gemfile)
54
- gem_names = parser.specs.map(&:name)
54
+ gem_info = parser.specs.map { |spec| GemInfo.from_spec(spec) }
55
55
  say("Done", :green)
56
- gem_names
56
+ gem_info
57
57
  end
58
58
 
59
- sig { params(project_gems: T::Array[String]).void }
59
+ sig { params(project_gems: T::Array[GemInfo]).void }
60
60
  def remove_expired_annotations(project_gems)
61
61
  say("Removing annotations for gems that have been removed... ", [:blue, :bold])
62
62
 
63
63
  annotations = Pathname.glob(@outpath.join("*.rbi")).map { |f| f.basename(".*").to_s }
64
- expired = annotations - project_gems
64
+ expired = annotations - project_gems.map(&:name)
65
65
 
66
66
  if expired.empty?
67
67
  say(" Nothing to do")
@@ -109,14 +109,14 @@ module Tapioca
109
109
  index
110
110
  end
111
111
 
112
- sig { params(gem_names: T::Array[String]).returns(T::Array[String]) }
113
- def fetch_annotations(gem_names)
112
+ sig { params(project_gems: T::Array[GemInfo]).returns(T::Array[String]) }
113
+ def fetch_annotations(project_gems)
114
114
  say("Fetching gem annotations from central repository... ", [:blue, :bold])
115
- fetchable_gems = T.let(Hash.new { |h, k| h[k] = [] }, T::Hash[String, T::Array[String]])
115
+ fetchable_gems = T.let(Hash.new { |h, k| h[k] = [] }, T::Hash[GemInfo, T::Array[String]])
116
116
 
117
- gem_names.each_with_object(fetchable_gems) do |gem_name, hash|
117
+ project_gems.each_with_object(fetchable_gems) do |gem_info, hash|
118
118
  @indexes.each do |uri, index|
119
- T.must(hash[gem_name]) << uri if index.has_gem?(gem_name)
119
+ T.must(hash[gem_info]) << uri if index.has_gem?(gem_info.name)
120
120
  end
121
121
  end
122
122
 
@@ -127,13 +127,16 @@ module Tapioca
127
127
  end
128
128
 
129
129
  say("\n")
130
- fetched_gems = fetchable_gems.select { |gem_name, repo_uris| fetch_annotation(repo_uris, gem_name) }
130
+ fetched_gems = fetchable_gems.select { |gem_info, repo_uris| fetch_annotation(repo_uris, gem_info) }
131
131
  say("\nDone", :green)
132
- fetched_gems.keys.sort
132
+ fetched_gems.keys.map(&:name).sort
133
133
  end
134
134
 
135
- sig { params(repo_uris: T::Array[String], gem_name: String).void }
136
- def fetch_annotation(repo_uris, gem_name)
135
+ sig { params(repo_uris: T::Array[String], gem_info: GemInfo).void }
136
+ def fetch_annotation(repo_uris, gem_info)
137
+ gem_name = gem_info.name
138
+ gem_version = gem_info.version
139
+
137
140
  contents = repo_uris.map do |repo_uri|
138
141
  fetch_file(repo_uri, "#{CENTRAL_REPO_ANNOTATIONS_DIR}/#{gem_name}.rbi")
139
142
  end
@@ -142,6 +145,7 @@ module Tapioca
142
145
  return unless content
143
146
 
144
147
  content = apply_typed_override(gem_name, content)
148
+ content = filter_versions(gem_version, content)
145
149
  content = add_header(gem_name, content)
146
150
 
147
151
  say("\n Fetched #{set_color(gem_name, :yellow, :bold)}", :green)
@@ -221,6 +225,14 @@ module Tapioca
221
225
  Spoom::Sorbet::Sigils.update_sigil(content, strictness)
222
226
  end
223
227
 
228
+ sig { params(gem_version: ::Gem::Version, content: String).returns(String) }
229
+ def filter_versions(gem_version, content)
230
+ rbi = RBI::Parser.parse_string(content)
231
+ rbi.filter_versions!(gem_version)
232
+
233
+ rbi.string
234
+ end
235
+
224
236
  sig { params(gem_name: String, contents: T::Array[String]).returns(T.nilable(String)) }
225
237
  def merge_files(gem_name, contents)
226
238
  return if contents.empty?
@@ -190,7 +190,7 @@ module Tapioca
190
190
  # Grab all Spawn methods
191
191
  query_methods |= ActiveRecord::SpawnMethods.instance_methods(false)
192
192
  # Remove the ones we know are private API
193
- query_methods -= [:arel, :build_subquery, :construct_join_dependency, :extensions, :spawn]
193
+ query_methods -= [:all, :arel, :build_subquery, :construct_join_dependency, :extensions, :spawn]
194
194
  # Remove "group" which needs a custom return type for GroupChains
195
195
  query_methods -= [:group]
196
196
  # Remove "where" which needs a custom return type for WhereChains
@@ -231,7 +231,7 @@ module Tapioca
231
231
  "fetch_#{suffix}",
232
232
  class_method: true,
233
233
  parameters: parameters,
234
- return_type: type,
234
+ return_type: field.unique ? type : COLLECTION_TYPE.call(type),
235
235
  )
236
236
 
237
237
  klass.create_method(
@@ -0,0 +1,18 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Tapioca
5
+ class GemInfo < T::Struct
6
+ const :name, String
7
+ const :version, ::Gem::Version
8
+
9
+ class << self
10
+ extend(T::Sig)
11
+
12
+ sig { params(spec: Bundler::LazySpecification).returns(GemInfo) }
13
+ def from_spec(spec)
14
+ new(name: spec.name, version: spec.version)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -45,6 +45,7 @@ require "tapioca/helpers/env_helper"
45
45
 
46
46
  require "tapioca/repo_index"
47
47
  require "tapioca/gemfile"
48
+ require "tapioca/gem_info"
48
49
  require "tapioca/executor"
49
50
 
50
51
  require "tapioca/static/symbol_table_parser"
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Tapioca
5
- VERSION = "0.14.4"
5
+ VERSION = "0.15.0"
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tapioca
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.4
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ufuk Kayserilioglu
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: exe
13
13
  cert_chain: []
14
- date: 2024-06-20 00:00:00.000000000 Z
14
+ date: 2024-06-27 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler
@@ -228,6 +228,7 @@ files:
228
228
  - lib/tapioca/gem/listeners/subconstants.rb
229
229
  - lib/tapioca/gem/listeners/yard_doc.rb
230
230
  - lib/tapioca/gem/pipeline.rb
231
+ - lib/tapioca/gem_info.rb
231
232
  - lib/tapioca/gemfile.rb
232
233
  - lib/tapioca/helpers/cli_helper.rb
233
234
  - lib/tapioca/helpers/config_helper.rb