tapioca 0.17.5 → 0.17.7

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: 302108d7d02504d88d18e3b0ae4832e2fd6c891e83f6428d69d5c4f6773a3a73
4
- data.tar.gz: 646642051b0b9d8736ad30e45d0b1bcfbe82f92b980f0909c45dc7f2337e0ce1
3
+ metadata.gz: d003e839857cc260e7b1ab86fd4a48d93efc53e4a43ac9ccac6c85d9a89e63a1
4
+ data.tar.gz: 900f2d0369802b0fac34f60c04e3c238cd68e439c1d6d60f4b9ed5d8c82770f0
5
5
  SHA512:
6
- metadata.gz: c6a75f400e82b9f311f0f53713a843a94a3e444a6a52b09d83abd818226a058ec78f02e43b193e864fc90f895ecad0425e7b9d160aaa7c4681b354392a7ad594
7
- data.tar.gz: 831256628c364563d69fe8d742f9fe0a973e12275bdbb5498a6af83c664036aa199ec0a94bf9ba527d3165723bf17aa5852e9eb2b993ccc0ed7439ef0f663a68
6
+ metadata.gz: b2f68a283b2499203877730fb5f981ed1e6c09c686a6c3e59297bea18361b5dd2d1831581f7b3edce6cf38936819544feeeebe59b1747520738542b0ae606ffe
7
+ data.tar.gz: '09769a8ab2aac1763cadecd013c9979c58d750c052f94c26eccfcbbd0a7ca07e0cb027c18e3737e90b90e85d4bebfca2fb4e8e559fdd9c4a0dd472ce5e59ee77'
data/exe/tapioca CHANGED
@@ -27,4 +27,9 @@ end
27
27
 
28
28
  require_relative "../lib/tapioca/internal"
29
29
 
30
- Tapioca::Cli.start(ARGV)
30
+ begin
31
+ Tapioca::Cli.start(ARGV)
32
+ rescue Tapioca::Error => e
33
+ warn(e.message)
34
+ exit(1)
35
+ end
@@ -1,7 +1,7 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- RubyLsp::Addon.depend_on_ruby_lsp!(">= 0.23.10", "< 0.26")
4
+ RubyLsp::Addon.depend_on_ruby_lsp!(">= 0.23.10", "< 0.27")
5
5
 
6
6
  begin
7
7
  # The Tapioca add-on depends on the Rails add-on to add a runtime component to the runtime server. We can allow the
@@ -20,6 +20,7 @@ module RubyLsp
20
20
  # Load DSL extensions and compilers ahead of time, so that we don't have to pay the price of invoking
21
21
  # `Gem.find_files` on every execution, which is quite expensive
22
22
  with_notification_wrapper("load_compilers_and_extensions", "Loading DSL compilers") do
23
+ ::Tapioca::Dsl::Compiler.extend(T::Generic)
23
24
  @loader = ::Tapioca::Loaders::Dsl.new(
24
25
  tapioca_path: ::Tapioca::TAPIOCA_DIR,
25
26
  eager_load: false,
data/lib/tapioca/cli.rb CHANGED
@@ -353,7 +353,7 @@ module Tapioca
353
353
  default: {}
354
354
  def annotations
355
355
  if !options[:netrc] && options[:netrc_file]
356
- raise Thor::Error, set_color("Options `--no-netrc` and `--netrc-file` can't be used together", :bold, :red)
356
+ raise Tapioca::Error, set_color("Options `--no-netrc` and `--netrc-file` can't be used together", :bold, :red)
357
357
  end
358
358
 
359
359
  command = Commands::Annotations.new(
@@ -160,7 +160,7 @@ module Tapioca
160
160
  remove_file(filename) if File.file?(filename)
161
161
  end
162
162
 
163
- raise Thor::Error, ""
163
+ raise Tapioca::Error, ""
164
164
  end
165
165
 
166
166
  processable_constants
@@ -295,7 +295,7 @@ module Tapioca
295
295
  build_error_for_files(cause, diff_for_cause.map(&:first))
296
296
  end.join("\n")
297
297
 
298
- raise Thor::Error, <<~ERROR
298
+ raise Tapioca::Error, <<~ERROR
299
299
  #{set_color("RBI files are out-of-date. In your development environment, please run:", :green)}
300
300
  #{set_color("`#{default_command(command)}`", :green, :bold)}
301
301
  #{set_color("Once it is complete, be sure to commit and push any changes", :green)}
@@ -201,7 +201,7 @@ module Tapioca
201
201
  build_error_for_files(cause, diff_for_cause.map(&:first))
202
202
  end.join("\n")
203
203
 
204
- raise Thor::Error, <<~ERROR
204
+ raise Tapioca::Error, <<~ERROR
205
205
  #{set_color("RBI files are out-of-date. In your development environment, please run:", :green)}
206
206
  #{set_color("`#{default_command(command)}`", :green, :bold)}
207
207
  #{set_color("Once it is complete, be sure to commit and push any changes", :green)}
@@ -85,7 +85,7 @@ module Tapioca
85
85
  end
86
86
 
87
87
  if indexes.empty?
88
- raise Thor::Error, set_color("Can't fetch annotations without sources (no index fetched)", :bold, :red)
88
+ raise Tapioca::Error, set_color("Can't fetch annotations without sources (no index fetched)", :bold, :red)
89
89
  end
90
90
 
91
91
  indexes
@@ -49,7 +49,7 @@ module Tapioca
49
49
  result = sorbet("--no-config --print=payload-sources:#{payload_path}")
50
50
 
51
51
  unless result.status
52
- raise Thor::Error, <<~ERROR
52
+ raise Tapioca::Error, <<~ERROR
53
53
  "Sorbet failed to dump payload"
54
54
  #{result.err}
55
55
  ERROR
@@ -87,7 +87,7 @@ module Tapioca
87
87
  "\nPlease remove the duplicated definitions from #{@shim_rbi_dir} and #{@todo_rbi_file}", :red
88
88
  )
89
89
 
90
- raise Thor::Error, messages.join("\n")
90
+ raise Tapioca::Error, messages.join("\n")
91
91
  end
92
92
 
93
93
  say("\nNo duplicates found in shim RBIs", :green)
@@ -58,7 +58,7 @@ module Tapioca
58
58
  if gem.nil?
59
59
  next if @lsp_addon
60
60
 
61
- raise Thor::Error, set_color("Error: Cannot find gem '#{gem_name}'", :red)
61
+ raise Tapioca::Error, set_color("Error: Cannot find gem '#{gem_name}'", :red)
62
62
  end
63
63
 
64
64
  gems.concat(gem_dependencies(gem)) if @include_dependencies
@@ -116,7 +116,7 @@ module Tapioca
116
116
  mod.create_method(
117
117
  "build_#{role}",
118
118
  parameters: [create_rest_param("args", type: "T.untyped")],
119
- return_type: "T.any(#{types.join(", ")})",
119
+ return_type: types.size == 1 ? types.first : "T.any(#{types.join(", ")})",
120
120
  )
121
121
  end
122
122
 
@@ -836,7 +836,15 @@ module Tapioca
836
836
  end
837
837
  end
838
838
  when :ids
839
- create_common_method("ids", return_type: "Array")
839
+ if constant.table_exists?
840
+ primary_key_type = constant.type_for_attribute(constant.primary_key)
841
+ type = Tapioca::Dsl::Helpers::ActiveModelTypeHelper.type_for(primary_key_type)
842
+ type = RBIHelper.as_non_nilable_type(type)
843
+ create_common_method("ids", return_type: "T::Array[#{type}]")
844
+ else
845
+ create_common_method("ids", return_type: "Array")
846
+ end
847
+
840
848
  when :pick, :pluck
841
849
  create_common_method(
842
850
  method_name,
@@ -60,7 +60,7 @@ module Tapioca
60
60
  No classes/modules can be matched for RBI generation.
61
61
  Please check that the requested classes/modules include processable DSL methods.
62
62
  ERROR
63
- raise Thor::Error, ""
63
+ raise Tapioca::Error, ""
64
64
  end
65
65
 
66
66
  if defined?(::ActiveRecord::Base) && constants_to_process.any? { |c| ::ActiveRecord::Base > c }
@@ -82,7 +82,7 @@ module Tapioca
82
82
  report_error(msg)
83
83
  end
84
84
 
85
- raise Thor::Error, ""
85
+ raise Tapioca::Error, ""
86
86
  end
87
87
 
88
88
  result.compact
@@ -83,7 +83,7 @@ module Tapioca
83
83
  end.compact
84
84
 
85
85
  unless errors.empty?
86
- raise Thor::Error, build_error_message(config_file, errors)
86
+ raise Tapioca::Error, build_error_message(config_file, errors)
87
87
  end
88
88
  ensure
89
89
  @validating_config = false
@@ -128,7 +128,7 @@ module Tapioca
128
128
  update_gem_rbis_strictnesses(redef_errors, gem_dir)
129
129
  end
130
130
 
131
- Kernel.raise Thor::Error, error_messages.join("\n") if parse_errors.any?
131
+ Kernel.raise Tapioca::Error, error_messages.join("\n") if parse_errors.any?
132
132
  end
133
133
 
134
134
  private
@@ -43,7 +43,7 @@ Module.include(T::Sig)
43
43
  # Trigger the source transformation for each Ruby file being loaded.
44
44
  RequireHooks.source_transform(patterns: ["**/*.rb"]) do |path, source|
45
45
  # The source is most likely nil since no `source_transform` hook was triggered before this one.
46
- source ||= File.read(path)
46
+ source ||= File.read(path, encoding: "UTF-8")
47
47
 
48
48
  # For performance reasons, we only rewrite files that use Sorbet.
49
49
  if source =~ /^\s*#\s*typed: (ignore|false|true|strict|strong|__STDLIB_INTERNAL)/
@@ -53,12 +53,12 @@ end
53
53
  class Module
54
54
  prepend(Module.new do
55
55
  def singleton_method_added(method_name)
56
- Tapioca::Runtime::Trackers::MethodDefinition.register(method_name, singleton_class, caller_locations)
56
+ Tapioca::Runtime::Trackers::MethodDefinition.register(method_name, singleton_class, Kernel.caller_locations)
57
57
  super
58
58
  end
59
59
 
60
60
  def method_added(method_name)
61
- Tapioca::Runtime::Trackers::MethodDefinition.register(method_name, self, caller_locations)
61
+ Tapioca::Runtime::Trackers::MethodDefinition.register(method_name, self, Kernel.caller_locations)
62
62
  super
63
63
  end
64
64
  end)
@@ -16,7 +16,7 @@ module T
16
16
  def qualified_name_of(constant)
17
17
  name = NAME_METHOD.bind_call(constant)
18
18
  name = nil if name&.start_with?("#<")
19
- return if name.nil?
19
+ return "::T.untyped" if name.nil?
20
20
 
21
21
  if name.start_with?("::")
22
22
  name
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Tapioca
5
- VERSION = "0.17.5"
5
+ VERSION = "0.17.7"
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.17.5
4
+ version: 0.17.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ufuk Kayserilioglu