tapioca 0.17.7 → 0.17.8

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: d003e839857cc260e7b1ab86fd4a48d93efc53e4a43ac9ccac6c85d9a89e63a1
4
- data.tar.gz: 900f2d0369802b0fac34f60c04e3c238cd68e439c1d6d60f4b9ed5d8c82770f0
3
+ metadata.gz: 489bd75ab0b8322c633ee51dbdb7f0bf4701fbca5cf64401c418d8a7fb454418
4
+ data.tar.gz: 62e4137c4fb603186d93b2f470148f5a8b7baa73bcfb6ed8b000a519dc1f106a
5
5
  SHA512:
6
- metadata.gz: b2f68a283b2499203877730fb5f981ed1e6c09c686a6c3e59297bea18361b5dd2d1831581f7b3edce6cf38936819544feeeebe59b1747520738542b0ae606ffe
7
- data.tar.gz: '09769a8ab2aac1763cadecd013c9979c58d750c052f94c26eccfcbbd0a7ca07e0cb027c18e3737e90b90e85d4bebfca2fb4e8e559fdd9c4a0dd472ce5e59ee77'
6
+ metadata.gz: ef5107149d789dda2d5c426a14b611ab1062f8aaa919ec179805c95bf7ad7d22eaae368ac9e0ed86b61cfac38b5bbbfc2fa65fa262837ce22ff4ee054b5cbf31
7
+ data.tar.gz: e568320ce79f3e9afa07d1ea1fc58aa7aef422f782b77c4b93707016b680bd2e3c2c971b136016dbf754ed82199e461178467195166f2c7738dec40632ac5de1
@@ -39,14 +39,14 @@ module RubyLsp
39
39
  fork do
40
40
  with_notification_wrapper("route_dsl", "Generating route DSL RBIs") do
41
41
  constants = ::Tapioca::Dsl::Compilers::UrlHelpers.gather_constants
42
- dsl(constants.map(&:name), "--only=Tapioca::Dsl::Compilers::UrlHelpers", "ActiveSupportConcern")
42
+ dsl(constants.map(&:name))
43
43
  end
44
44
  end
45
45
  when "fixtures_dsl"
46
46
  fork do
47
47
  with_notification_wrapper("fixture_dsl", "Generating fixture DSL RBIs") do
48
48
  constants = ::Tapioca::Dsl::Compilers::ActiveRecordFixtures.gather_constants
49
- dsl(constants.map(&:name), "--only=Tapioca::Dsl::Compilers::ActiveRecordFixtures")
49
+ dsl(constants.map(&:name))
50
50
  end
51
51
  end
52
52
  end
@@ -60,7 +60,7 @@ module RubyLsp
60
60
  end
61
61
  end
62
62
 
63
- def dsl(constants, *args)
63
+ def dsl(constants)
64
64
  load("tapioca/cli.rb") # Reload the CLI to reset thor defaults between requests
65
65
 
66
66
  ::Tapioca::Cli.addon_mode!
@@ -68,7 +68,6 @@ module RubyLsp
68
68
  # Order here is important to avoid having Thor confuse arguments. Do not put an array argument at the end before
69
69
  # the list of constants
70
70
  arguments = ["dsl"]
71
- arguments.concat(args)
72
71
  arguments.push("--workers=1")
73
72
  arguments.concat(constants)
74
73
 
data/lib/tapioca/cli.rb CHANGED
@@ -301,6 +301,7 @@ module Tapioca
301
301
  rbi_formatter: rbi_formatter(options),
302
302
  halt_upon_load_error: options[:halt_upon_load_error],
303
303
  lsp_addon: options[:lsp_addon],
304
+ verbose: options[:verbose],
304
305
  }
305
306
 
306
307
  command = if verify
@@ -8,7 +8,7 @@ module Tapioca
8
8
  include SorbetHelper
9
9
  include RBIFilesHelper
10
10
 
11
- #: (gem_names: Array[String], exclude: Array[String], include_dependencies: bool, prerequire: String?, postrequire: String, typed_overrides: Hash[String, String], outpath: Pathname, file_header: bool, include_doc: bool, include_loc: bool, include_exported_rbis: bool, ?number_of_workers: Integer?, ?auto_strictness: bool, ?dsl_dir: String, ?rbi_formatter: RBIFormatter, ?halt_upon_load_error: bool, ?lsp_addon: bool?) -> void
11
+ #: (gem_names: Array[String], exclude: Array[String], include_dependencies: bool, prerequire: String?, postrequire: String, typed_overrides: Hash[String, String], outpath: Pathname, file_header: bool, include_doc: bool, include_loc: bool, include_exported_rbis: bool, ?number_of_workers: Integer?, ?auto_strictness: bool, ?dsl_dir: String, ?rbi_formatter: RBIFormatter, ?halt_upon_load_error: bool, ?lsp_addon: bool?, ?verbose: bool?) -> void
12
12
  def initialize(
13
13
  gem_names:,
14
14
  exclude:,
@@ -26,7 +26,8 @@ module Tapioca
26
26
  dsl_dir: DEFAULT_DSL_DIR,
27
27
  rbi_formatter: DEFAULT_RBI_FORMATTER,
28
28
  halt_upon_load_error: true,
29
- lsp_addon: false
29
+ lsp_addon: false,
30
+ verbose: false
30
31
  )
31
32
  @gem_names = gem_names
32
33
  @exclude = exclude
@@ -41,6 +42,7 @@ module Tapioca
41
42
  @dsl_dir = dsl_dir
42
43
  @rbi_formatter = rbi_formatter
43
44
  @lsp_addon = lsp_addon
45
+ @verbose = verbose
44
46
 
45
47
  super()
46
48
 
@@ -58,6 +60,7 @@ module Tapioca
58
60
  #: (Gemfile::GemSpec gem) -> void
59
61
  def compile_gem_rbi(gem)
60
62
  gem_name = set_color(gem.name, :yellow, :bold)
63
+ say("Currently compiling #{gem_name}", :cyan) if @verbose
61
64
 
62
65
  rbi = RBI::File.new(strictness: @typed_overrides[gem.name] || "true")
63
66
 
@@ -67,7 +70,7 @@ module Tapioca
67
70
  reason: "types exported from the `#{gem.name}` gem",
68
71
  ) if @file_header
69
72
 
70
- rbi.root = Runtime::Trackers::Autoload.with_disabled_exits do
73
+ rbi.root = Tapioca.with_disabled_exits do
71
74
  Tapioca::Gem::Pipeline.new(
72
75
  gem,
73
76
  include_doc: @include_doc,
@@ -41,10 +41,11 @@ module Tapioca
41
41
 
42
42
  #: -> Array[GemInfo]
43
43
  def list_gemfile_gems
44
- say("Listing gems from Gemfile.lock... ", [:blue, :bold])
45
- gemfile = Bundler.read_file("Gemfile.lock")
46
- parser = Bundler::LockfileParser.new(gemfile)
47
- gem_info = parser.specs.map { |spec| GemInfo.from_spec(spec) }
44
+ lockfile_path = Bundler.definition.lockfile.basename
45
+ say("Listing gems from #{lockfile_path}... ", [:blue, :bold])
46
+
47
+ specs = Bundler.definition.specs
48
+ gem_info = specs.map { |spec| GemInfo.from_spec(spec) }
48
49
  say("Done", :green)
49
50
  gem_info
50
51
  end
@@ -26,12 +26,16 @@ module Tapioca
26
26
  # # typed: true
27
27
  #
28
28
  # class Shop
29
+ # include GeneratedAttributeMethods
29
30
  #
30
- # sig { returns(T.nilable(::String)) }
31
- # def name; end
31
+ # module GeneratedAttributeMethods
32
+ # sig { returns(T.nilable(::String)) }
33
+ # def name; end
34
+ #
35
+ # sig { params(name: T.nilable(::String)).returns(T.nilable(::String)) }
36
+ # def name=(name); end
37
+ # end
32
38
  #
33
- # sig { params(name: T.nilable(::String)).returns(T.nilable(::String)) }
34
- # def name=(name); end
35
39
  # end
36
40
  # ~~~
37
41
  #: [ConstantType = (Class[::ActiveModel::Attributes] & ::ActiveModel::Attributes::ClassMethods)]
@@ -45,9 +49,13 @@ module Tapioca
45
49
  return if attribute_methods.empty?
46
50
 
47
51
  root.create_path(constant) do |klass|
48
- attribute_methods.each do |method, attribute_type|
49
- generate_method(klass, method, attribute_type)
52
+ klass.create_module("GeneratedAttributeMethods") do |mod|
53
+ attribute_methods.each do |method, attribute_type|
54
+ generate_method(mod, method, attribute_type)
55
+ end
50
56
  end
57
+
58
+ klass.create_include("GeneratedAttributeMethods")
51
59
  end
52
60
  end
53
61
 
@@ -4,6 +4,7 @@
4
4
  return unless defined?(ActiveRecord::Base)
5
5
 
6
6
  require "tapioca/dsl/helpers/active_model_type_helper"
7
+ require "tapioca/dsl/helpers/active_record_column_type_helper"
7
8
  require "tapioca/dsl/helpers/active_record_constants_helper"
8
9
 
9
10
  module Tapioca
@@ -837,9 +838,13 @@ module Tapioca
837
838
  end
838
839
  when :ids
839
840
  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)
841
+ column_type_helper = Tapioca::Dsl::Helpers::ActiveRecordColumnTypeHelper.new(
842
+ constant,
843
+ column_type_option: Tapioca::Dsl::Helpers::ActiveRecordColumnTypeHelper::ColumnTypeOption::Persisted,
844
+ )
845
+ primary_key = constant.primary_key
846
+ getter_type, _setter_type = column_type_helper.type_for(primary_key)
847
+ type = getter_type
843
848
  create_common_method("ids", return_type: "T::Array[#{type}]")
844
849
  else
845
850
  create_common_method("ids", return_type: "Array")
@@ -98,7 +98,13 @@ module Tapioca
98
98
  # inherited ancestors, past the location of the constant itself.
99
99
  ancestors = Set.new.compare_by_identity.merge(ancestors_of(constant))
100
100
 
101
- (ancestors - inherited_ancestors).to_a
101
+ result = (ancestors - inherited_ancestors).to_a
102
+
103
+ # Filter out Kernel for modules (but not classes) since modules shouldn't
104
+ # need to explicitly include Kernel in RBIs
105
+ result.delete(Kernel) unless Class === constant
106
+
107
+ result
102
108
  end
103
109
  end
104
110
  end
@@ -32,7 +32,7 @@ module Tapioca
32
32
 
33
33
  #: (String line) -> bool
34
34
  def rbs_comment?(line)
35
- line.strip.start_with?(": ", "| ")
35
+ line.start_with?(": ", "| ")
36
36
  end
37
37
 
38
38
  # @override
@@ -74,7 +74,7 @@ module Tapioca
74
74
 
75
75
  comments << RBI::Comment.new("") if comments.any? && tags.any?
76
76
 
77
- tags.sort_by(&:tag_name).each do |tag|
77
+ tags.sort_by { |tag| [tag.tag_name, tag.name.to_s] }.each do |tag|
78
78
  line = +"@#{tag.tag_name}"
79
79
 
80
80
  tag_name = tag.name
@@ -9,7 +9,7 @@ module Tapioca
9
9
  class << self
10
10
  extend(T::Sig)
11
11
 
12
- #: (Bundler::LazySpecification spec) -> GemInfo
12
+ #: (::Bundler::StubSpecification | ::Gem::Specification spec) -> GemInfo
13
13
  def from_spec(spec)
14
14
  new(name: spec.name, version: spec.version)
15
15
  end
@@ -44,13 +44,20 @@ module Tapioca
44
44
  #: -> void
45
45
  def require_gem_file
46
46
  say("Requiring all gems to prepare for compiling... ")
47
- begin
47
+
48
+ bundle_loaded = true #: bool
49
+
50
+ Tapioca.with_disabled_exits do
48
51
  load_bundle(@bundle, @prerequire, @postrequire, @halt_upon_load_error)
49
52
  rescue LoadError => e
53
+ bundle_loaded = false
50
54
  explain_failed_require(@postrequire, e)
51
- exit(1)
52
55
  end
53
56
 
57
+ # Can't call exit in the rescue block above, since it will be disabled,
58
+ # so we check the flag after the block.
59
+ exit(1) unless bundle_loaded
60
+
54
61
  Runtime::Trackers::Autoload.eager_load_all!
55
62
 
56
63
  say(" Done", :green)
@@ -8,8 +8,6 @@ module Tapioca
8
8
  extend Tracker
9
9
  extend T::Sig
10
10
 
11
- NOOP_METHOD = ->(*_args, **_kwargs, &_block) {}
12
-
13
11
  @constant_names_registered_for_autoload = [] #: Array[String]
14
12
 
15
13
  class << self
@@ -17,7 +15,7 @@ module Tapioca
17
15
 
18
16
  #: -> void
19
17
  def eager_load_all!
20
- with_disabled_exits do
18
+ Tapioca.with_disabled_exits do
21
19
  until @constant_names_registered_for_autoload.empty?
22
20
  # Grab the next constant name
23
21
  constant_name = T.must(@constant_names_registered_for_autoload.shift)
@@ -33,24 +31,6 @@ module Tapioca
33
31
 
34
32
  @constant_names_registered_for_autoload << constant_name
35
33
  end
36
-
37
- #: [Result] { -> Result } -> Result
38
- def with_disabled_exits(&block)
39
- original_abort = Kernel.instance_method(:abort)
40
- original_exit = Kernel.instance_method(:exit)
41
-
42
- begin
43
- Kernel.define_method(:abort, NOOP_METHOD)
44
- Kernel.define_method(:exit, NOOP_METHOD)
45
-
46
- Tapioca.silence_warnings do
47
- block.call
48
- end
49
- ensure
50
- Kernel.define_method(:exit, original_exit)
51
- Kernel.define_method(:abort, original_abort)
52
- end
53
- end
54
34
  end
55
35
  end
56
36
  end
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Tapioca
5
- VERSION = "0.17.7"
5
+ VERSION = "0.17.8"
6
6
  end
data/lib/tapioca.rb CHANGED
@@ -9,6 +9,9 @@ module Tapioca
9
9
 
10
10
  @traces = [] #: Array[TracePoint]
11
11
 
12
+ NOOP_METHOD = ->(*_args, **_kwargs, &_block) {} #: ^() -> void
13
+ private_constant :NOOP_METHOD
14
+
12
15
  class << self
13
16
  extend T::Sig
14
17
 
@@ -22,6 +25,24 @@ module Tapioca
22
25
  ensure
23
26
  $VERBOSE = original_verbosity
24
27
  end
28
+
29
+ #: [Result] { -> Result } -> Result
30
+ def with_disabled_exits(&block)
31
+ original_abort = Kernel.instance_method(:abort)
32
+ original_exit = Kernel.instance_method(:exit)
33
+
34
+ begin
35
+ Kernel.define_method(:abort, NOOP_METHOD)
36
+ Kernel.define_method(:exit, NOOP_METHOD)
37
+
38
+ Tapioca.silence_warnings do
39
+ block.call
40
+ end
41
+ ensure
42
+ Kernel.define_method(:exit, original_exit)
43
+ Kernel.define_method(:abort, original_abort)
44
+ end
45
+ end
25
46
  end
26
47
 
27
48
  class Error < StandardError; 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.7
4
+ version: 0.17.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ufuk Kayserilioglu
@@ -316,7 +316,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
316
316
  - !ruby/object:Gem::Version
317
317
  version: '0'
318
318
  requirements: []
319
- rubygems_version: 3.6.9
319
+ rubygems_version: 3.7.2
320
320
  specification_version: 4
321
321
  summary: A Ruby Interface file generator for gems, core types and the Ruby standard
322
322
  library