tapioca 0.4.2 → 0.4.3

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: 46bdcc628673ddc597495e267b471e3a6f4c705b8f8d8d32dffba17c69470c21
4
- data.tar.gz: 4a2e597d03ea9354835e73f52034d088b1c15ac65f445d0f6963bbbca09c2b23
3
+ metadata.gz: ffc5e922b8cd11f0667bfe31aa52ffc1087d954e0de34fbf97bcd54f65f522df
4
+ data.tar.gz: 25b67e05f26e1c6eb9e1e9723d1d6ed853986e658f389da74203349b99fca1c2
5
5
  SHA512:
6
- metadata.gz: 51c134a7948c262721672f61105e08e1e31146b70d982fac0944b0d42be91d5e2210a110775596d11704e60eac68d6b2e27c016587777c658fab2b64131f7a1e
7
- data.tar.gz: 1f048066d59bc2cc08a62fb93de96afdb7146d8e1c987c2a98677edd4920b08896096f9beaa658466ebd54be729c2bf6947ef1c409ab7329dac5ac27f7847dbc
6
+ metadata.gz: 1334f75cb44c365c0dd075e2aa52c65bd4b685634376a2b06db9de2c6d3d809997957568f6a14006ccb984cf845e267bf75c027906f20ee9546643e9f968462f
7
+ data.tar.gz: adad8cf61d2810cb823739616c77cbf4ac2d88a88d2fac60c84c837764cdd3940376815ee446b931e2ebe9ab41ac2b48daeb519db4892f680f9aeb2fa6888db4
@@ -4,10 +4,12 @@
4
4
  require "sorbet-runtime"
5
5
 
6
6
  module Tapioca
7
- def self.silence_warnings
7
+ def self.silence_warnings(&blk)
8
8
  original_verbosity = $VERBOSE
9
9
  $VERBOSE = nil
10
- yield
10
+ Gem::DefaultUserInteraction.use_ui(Gem::SilentUI.new) do
11
+ blk.call
12
+ end
11
13
  ensure
12
14
  $VERBOSE = original_verbosity
13
15
  end
@@ -6,6 +6,7 @@ require "parlour"
6
6
  begin
7
7
  require "rails"
8
8
  require "action_controller"
9
+ require "action_view"
9
10
  rescue LoadError
10
11
  return
11
12
  end
@@ -29,13 +30,18 @@ module Tapioca
29
30
  end
30
31
  end
31
32
 
32
- sig { override.returns(T::Enumerable[T.untyped]) }
33
+ NON_DISCOVERABLE_INCLUDERS = T.let([
34
+ ActionDispatch::IntegrationTest,
35
+ ActionView::Helpers,
36
+ ], T::Array[Module])
37
+
38
+ sig { override.returns(T::Enumerable[Module]) }
33
39
  def gather_constants
34
40
  Object.const_set(:GeneratedUrlHelpersModule, Rails.application.routes.named_routes.url_helpers_module)
35
41
  Object.const_set(:GeneratedPathHelpersModule, Rails.application.routes.named_routes.path_helpers_module)
36
42
 
37
- constants = ObjectSpace.each_object(Module).select do |mod|
38
- mod = T.cast(mod, T.class_of(Module))
43
+ module_enumerator = T.cast(ObjectSpace.each_object(Module), T::Enumerator[Module])
44
+ constants = module_enumerator.select do |mod|
39
45
  next unless Module.instance_method(:name).bind(mod).call
40
46
 
41
47
  includes_helper?(mod, GeneratedUrlHelpersModule) ||
@@ -44,7 +50,7 @@ module Tapioca
44
50
  includes_helper?(mod.singleton_class, GeneratedPathHelpersModule)
45
51
  end
46
52
 
47
- constants << ActionDispatch::IntegrationTest
53
+ constants.concat(NON_DISCOVERABLE_INCLUDERS)
48
54
  end
49
55
 
50
56
  private
@@ -67,8 +73,11 @@ module Tapioca
67
73
 
68
74
  sig { params(mod: Parlour::RbiGenerator::Namespace, constant: T.class_of(Module), helper_module: Module).void }
69
75
  def create_mixins_for(mod, constant, helper_module)
70
- mod.create_include(T.must(helper_module.name)) if constant.ancestors.include?(helper_module)
71
- mod.create_extend(T.must(helper_module.name)) if constant.singleton_class.ancestors.include?(helper_module)
76
+ include_helper = constant.ancestors.include?(helper_module) || NON_DISCOVERABLE_INCLUDERS.include?(constant)
77
+ extend_helper = constant.singleton_class.ancestors.include?(helper_module)
78
+
79
+ mod.create_include(T.must(helper_module.name)) if include_helper
80
+ mod.create_extend(T.must(helper_module.name)) if extend_helper
72
81
  end
73
82
 
74
83
  sig { params(mod: Module, helper: Module).returns(T::Boolean) }
@@ -503,7 +503,27 @@ module Tapioca
503
503
 
504
504
  params = T.let(method.parameters, T::Array[T::Array[Symbol]])
505
505
  parameters = params.map do |(type, name)|
506
- name ||= :_
506
+ unless name
507
+ # For attr_writer methods, Sorbet signatures have the name
508
+ # of the method (without the trailing = sign) as the name of
509
+ # the only parameter. So, if the parameter does not have a name
510
+ # then the replacement name should be the name of the method
511
+ # (minus trailing =) if and only if there is a signature for the
512
+ # method and the parameter is required and there is a single
513
+ # parameter and the signature also defines a single parameter and
514
+ # the name of the method ends with a = character.
515
+ writer_method_with_sig = signature &&
516
+ type == :req &&
517
+ params.size == 1 &&
518
+ signature.arg_types.size == 1 &&
519
+ method_name[-1] == "="
520
+
521
+ name = if writer_method_with_sig
522
+ method_name[0...-1].to_sym
523
+ else
524
+ :_
525
+ end
526
+ end
507
527
 
508
528
  # Sanitize param names
509
529
  name = name.to_s.gsub(/[^a-zA-Z0-9_]/, '_')
@@ -99,6 +99,16 @@ module Tapioca
99
99
 
100
100
  sig { void }
101
101
  def eager_load_rails_app
102
+ if Object.const_defined?("ActiveSupport")
103
+ Object.const_get("ActiveSupport").run_load_hooks(
104
+ :before_eager_load,
105
+ Object.const_get("Rails").application
106
+ )
107
+ end
108
+ if Object.const_defined?("Zeitwerk::Loader")
109
+ zeitwerk_loader = Object.const_get("Zeitwerk::Loader")
110
+ zeitwerk_loader.eager_load_all
111
+ end
102
112
  Object.const_get("Rails").autoloaders.each(&:eager_load)
103
113
  end
104
114
 
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Tapioca
5
- VERSION = "0.4.2"
5
+ VERSION = "0.4.3"
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.4.2
4
+ version: 0.4.3
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: 2020-08-18 00:00:00.000000000 Z
14
+ date: 2020-08-19 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: pry