tapioca 0.4.24 → 0.5.1
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 +4 -4
 - data/Gemfile +14 -14
 - data/README.md +2 -2
 - data/Rakefile +5 -7
 - data/exe/tapioca +2 -2
 - data/lib/tapioca/cli.rb +256 -2
 - data/lib/tapioca/compilers/dsl/aasm.rb +122 -0
 - data/lib/tapioca/compilers/dsl/action_controller_helpers.rb +52 -12
 - data/lib/tapioca/compilers/dsl/action_mailer.rb +6 -9
 - data/lib/tapioca/compilers/dsl/active_job.rb +8 -12
 - data/lib/tapioca/compilers/dsl/active_model_attributes.rb +131 -0
 - data/lib/tapioca/compilers/dsl/active_record_associations.rb +33 -54
 - data/lib/tapioca/compilers/dsl/active_record_columns.rb +10 -105
 - data/lib/tapioca/compilers/dsl/active_record_enum.rb +8 -10
 - data/lib/tapioca/compilers/dsl/active_record_scope.rb +7 -10
 - data/lib/tapioca/compilers/dsl/active_record_typed_store.rb +5 -8
 - data/lib/tapioca/compilers/dsl/active_resource.rb +9 -37
 - data/lib/tapioca/compilers/dsl/active_storage.rb +98 -0
 - data/lib/tapioca/compilers/dsl/active_support_concern.rb +108 -0
 - data/lib/tapioca/compilers/dsl/active_support_current_attributes.rb +13 -8
 - data/lib/tapioca/compilers/dsl/base.rb +96 -82
 - data/lib/tapioca/compilers/dsl/config.rb +111 -0
 - data/lib/tapioca/compilers/dsl/frozen_record.rb +5 -7
 - data/lib/tapioca/compilers/dsl/identity_cache.rb +66 -29
 - data/lib/tapioca/compilers/dsl/protobuf.rb +19 -69
 - data/lib/tapioca/compilers/dsl/sidekiq_worker.rb +25 -12
 - data/lib/tapioca/compilers/dsl/smart_properties.rb +19 -31
 - data/lib/tapioca/compilers/dsl/state_machines.rb +56 -78
 - data/lib/tapioca/compilers/dsl/url_helpers.rb +7 -10
 - data/lib/tapioca/compilers/dsl_compiler.rb +22 -38
 - data/lib/tapioca/compilers/requires_compiler.rb +2 -2
 - data/lib/tapioca/compilers/sorbet.rb +26 -5
 - data/lib/tapioca/compilers/symbol_table/symbol_generator.rb +139 -154
 - data/lib/tapioca/compilers/symbol_table/symbol_loader.rb +4 -4
 - data/lib/tapioca/compilers/symbol_table_compiler.rb +1 -1
 - data/lib/tapioca/compilers/todos_compiler.rb +1 -1
 - data/lib/tapioca/config.rb +2 -0
 - data/lib/tapioca/config_builder.rb +4 -2
 - data/lib/tapioca/constant_locator.rb +6 -8
 - data/lib/tapioca/gemfile.rb +26 -19
 - data/lib/tapioca/generator.rb +127 -43
 - data/lib/tapioca/generic_type_registry.rb +25 -98
 - data/lib/tapioca/helpers/active_record_column_type_helper.rb +98 -0
 - data/lib/tapioca/internal.rb +1 -9
 - data/lib/tapioca/loader.rb +14 -48
 - data/lib/tapioca/rbi_ext/model.rb +122 -0
 - data/lib/tapioca/reflection.rb +131 -0
 - data/lib/tapioca/sorbet_ext/fixed_hash_patch.rb +1 -1
 - data/lib/tapioca/sorbet_ext/generic_name_patch.rb +72 -4
 - data/lib/tapioca/sorbet_ext/name_patch.rb +1 -1
 - data/lib/tapioca/version.rb +1 -1
 - data/lib/tapioca.rb +2 -0
 - metadata +34 -22
 - data/lib/tapioca/cli/main.rb +0 -146
 - data/lib/tapioca/core_ext/class.rb +0 -28
 - data/lib/tapioca/core_ext/string.rb +0 -18
 - data/lib/tapioca/rbi/model.rb +0 -405
 - data/lib/tapioca/rbi/printer.rb +0 -410
 - data/lib/tapioca/rbi/rewriters/group_nodes.rb +0 -106
 - data/lib/tapioca/rbi/rewriters/nest_non_public_methods.rb +0 -65
 - data/lib/tapioca/rbi/rewriters/nest_singleton_methods.rb +0 -42
 - data/lib/tapioca/rbi/rewriters/sort_nodes.rb +0 -86
 - data/lib/tapioca/rbi/visitor.rb +0 -21
 
| 
         @@ -1,8 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # typed: strict
         
     | 
| 
       2 
2 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
            require "parlour"
         
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
4 
     | 
    
         
             
            begin
         
     | 
| 
       7 
5 
     | 
    
         
             
              require "smart_properties"
         
     | 
| 
       8 
6 
     | 
    
         
             
            rescue LoadError
         
     | 
| 
         @@ -55,7 +53,7 @@ module Tapioca 
     | 
|
| 
       55 
53 
     | 
    
         
             
                  #   sig { params(published: T.nilable(T::Boolean)).returns(T.nilable(T::Boolean)) }
         
     | 
| 
       56 
54 
     | 
    
         
             
                  #   def published=(published); end
         
     | 
| 
       57 
55 
     | 
    
         
             
                  #
         
     | 
| 
       58 
     | 
    
         
            -
                  #    
     | 
| 
      
 56 
     | 
    
         
            +
                  #   sig { returns(T.nilable(T::Boolean)) }
         
     | 
| 
       59 
57 
     | 
    
         
             
                  #   def enabled; end
         
     | 
| 
       60 
58 
     | 
    
         
             
                  #
         
     | 
| 
       61 
59 
     | 
    
         
             
                  #   sig { params(enabled: T.nilable(T::Boolean)).returns(T.nilable(T::Boolean)) }
         
     | 
| 
         @@ -65,14 +63,7 @@ module Tapioca 
     | 
|
| 
       65 
63 
     | 
    
         
             
                  class SmartProperties < Base
         
     | 
| 
       66 
64 
     | 
    
         
             
                    extend T::Sig
         
     | 
| 
       67 
65 
     | 
    
         | 
| 
       68 
     | 
    
         
            -
                    sig  
     | 
| 
       69 
     | 
    
         
            -
                      override
         
     | 
| 
       70 
     | 
    
         
            -
                        .params(
         
     | 
| 
       71 
     | 
    
         
            -
                          root: Parlour::RbiGenerator::Namespace,
         
     | 
| 
       72 
     | 
    
         
            -
                          constant: T.class_of(::SmartProperties)
         
     | 
| 
       73 
     | 
    
         
            -
                        )
         
     | 
| 
       74 
     | 
    
         
            -
                        .void
         
     | 
| 
       75 
     | 
    
         
            -
                    end
         
     | 
| 
      
 66 
     | 
    
         
            +
                    sig { override.params(root: RBI::Tree, constant: T.class_of(::SmartProperties)).void }
         
     | 
| 
       76 
67 
     | 
    
         
             
                    def decorate(root, constant)
         
     | 
| 
       77 
68 
     | 
    
         
             
                      properties = T.let(
         
     | 
| 
       78 
69 
     | 
    
         
             
                        T.unsafe(constant).properties,
         
     | 
| 
         @@ -82,7 +73,7 @@ module Tapioca 
     | 
|
| 
       82 
73 
     | 
    
         | 
| 
       83 
74 
     | 
    
         
             
                      instance_methods = constant.instance_methods(false).map(&:to_s).to_set
         
     | 
| 
       84 
75 
     | 
    
         | 
| 
       85 
     | 
    
         
            -
                      root. 
     | 
| 
      
 76 
     | 
    
         
            +
                      root.create_path(constant) do |k|
         
     | 
| 
       86 
77 
     | 
    
         
             
                        properties.values.each do |property|
         
     | 
| 
       87 
78 
     | 
    
         
             
                          generate_methods_for_property(k, property) do |method_name|
         
     | 
| 
       88 
79 
     | 
    
         
             
                            !instance_methods.include?(method_name.to_sym)
         
     | 
| 
         @@ -93,11 +84,10 @@ module Tapioca 
     | 
|
| 
       93 
84 
     | 
    
         | 
| 
       94 
85 
     | 
    
         
             
                    sig { override.returns(T::Enumerable[Module]) }
         
     | 
| 
       95 
86 
     | 
    
         
             
                    def gather_constants
         
     | 
| 
       96 
     | 
    
         
            -
                       
     | 
| 
       97 
     | 
    
         
            -
                      classes.select do |c|
         
     | 
| 
      
 87 
     | 
    
         
            +
                      all_classes.select do |c|
         
     | 
| 
       98 
88 
     | 
    
         
             
                        c < ::SmartProperties
         
     | 
| 
       99 
89 
     | 
    
         
             
                      end.reject do |c|
         
     | 
| 
       100 
     | 
    
         
            -
                        c. 
     | 
| 
      
 90 
     | 
    
         
            +
                        name_of(c).nil? || c == ::SmartProperties::Validations::Ancestor
         
     | 
| 
       101 
91 
     | 
    
         
             
                      end
         
     | 
| 
       102 
92 
     | 
    
         
             
                    end
         
     | 
| 
       103 
93 
     | 
    
         | 
| 
         @@ -105,7 +95,7 @@ module Tapioca 
     | 
|
| 
       105 
95 
     | 
    
         | 
| 
       106 
96 
     | 
    
         
             
                    sig do
         
     | 
| 
       107 
97 
     | 
    
         
             
                      params(
         
     | 
| 
       108 
     | 
    
         
            -
                        klass:  
     | 
| 
      
 98 
     | 
    
         
            +
                        klass: RBI::Scope,
         
     | 
| 
       109 
99 
     | 
    
         
             
                        property: ::SmartProperties::Property,
         
     | 
| 
       110 
100 
     | 
    
         
             
                        block: T.proc.params(arg: String).returns(T::Boolean)
         
     | 
| 
       111 
101 
     | 
    
         
             
                      ).void
         
     | 
| 
         @@ -119,7 +109,7 @@ module Tapioca 
     | 
|
| 
       119 
109 
     | 
    
         | 
| 
       120 
110 
     | 
    
         
             
                        klass.create_method(
         
     | 
| 
       121 
111 
     | 
    
         
             
                          method_name,
         
     | 
| 
       122 
     | 
    
         
            -
                          parameters: [ 
     | 
| 
      
 112 
     | 
    
         
            +
                          parameters: [create_param(name, type: type)],
         
     | 
| 
       123 
113 
     | 
    
         
             
                          return_type: type
         
     | 
| 
       124 
114 
     | 
    
         
             
                        ) if block.call(method_name)
         
     | 
| 
       125 
115 
     | 
    
         
             
                      end
         
     | 
| 
         @@ -134,10 +124,13 @@ module Tapioca 
     | 
|
| 
       134 
124 
     | 
    
         | 
| 
       135 
125 
     | 
    
         
             
                    sig { params(property: ::SmartProperties::Property).returns(String) }
         
     | 
| 
       136 
126 
     | 
    
         
             
                    def type_for(property)
         
     | 
| 
       137 
     | 
    
         
            -
                      converter = property. 
     | 
| 
       138 
     | 
    
         
            -
             
     | 
| 
      
 127 
     | 
    
         
            +
                      converter, accepter, required = property.to_h.fetch_values(
         
     | 
| 
      
 128 
     | 
    
         
            +
                        :converter,
         
     | 
| 
      
 129 
     | 
    
         
            +
                        :accepter,
         
     | 
| 
      
 130 
     | 
    
         
            +
                        :required,
         
     | 
| 
      
 131 
     | 
    
         
            +
                      )
         
     | 
| 
       139 
132 
     | 
    
         | 
| 
       140 
     | 
    
         
            -
                       
     | 
| 
      
 133 
     | 
    
         
            +
                      return "T.untyped" if converter
         
     | 
| 
       141 
134 
     | 
    
         | 
| 
       142 
135 
     | 
    
         
             
                      type = if accepter.nil? || accepter.respond_to?(:to_proc)
         
     | 
| 
       143 
136 
     | 
    
         
             
                        "T.untyped"
         
     | 
| 
         @@ -147,25 +140,20 @@ module Tapioca 
     | 
|
| 
       147 
140 
     | 
    
         
             
                        "T::Boolean"
         
     | 
| 
       148 
141 
     | 
    
         
             
                      elsif Array(accepter).all? { |a| a.is_a?(Module) }
         
     | 
| 
       149 
142 
     | 
    
         
             
                        accepters = Array(accepter)
         
     | 
| 
       150 
     | 
    
         
            -
                        types = accepters.map { |mod|  
     | 
| 
      
 143 
     | 
    
         
            +
                        types = accepters.map { |mod| T.must(qualified_name_of(mod)) }.join(", ")
         
     | 
| 
       151 
144 
     | 
    
         
             
                        types = "T.any(#{types})" if accepters.size > 1
         
     | 
| 
       152 
145 
     | 
    
         
             
                        types
         
     | 
| 
       153 
146 
     | 
    
         
             
                      else
         
     | 
| 
       154 
147 
     | 
    
         
             
                        "T.untyped"
         
     | 
| 
       155 
148 
     | 
    
         
             
                      end
         
     | 
| 
       156 
149 
     | 
    
         | 
| 
       157 
     | 
    
         
            -
                       
     | 
| 
       158 
     | 
    
         
            -
                       
     | 
| 
       159 
     | 
    
         
            -
                      property_required = type == "T.untyped" || required
         
     | 
| 
       160 
     | 
    
         
            -
                      type = "T.nilable(#{type})" unless property_required
         
     | 
| 
      
 150 
     | 
    
         
            +
                      # Early return for "T.untyped", nothing more to do.
         
     | 
| 
      
 151 
     | 
    
         
            +
                      return type if type == "T.untyped"
         
     | 
| 
       161 
152 
     | 
    
         | 
| 
       162 
     | 
    
         
            -
                       
     | 
| 
       163 
     | 
    
         
            -
             
     | 
| 
      
 153 
     | 
    
         
            +
                      might_be_optional = Proc === required || !required
         
     | 
| 
      
 154 
     | 
    
         
            +
                      type = "T.nilable(#{type})" if might_be_optional
         
     | 
| 
       164 
155 
     | 
    
         | 
| 
       165 
     | 
    
         
            -
             
     | 
| 
       166 
     | 
    
         
            -
                    def name_of(type)
         
     | 
| 
       167 
     | 
    
         
            -
                      name = Module.instance_method(:name).bind(type).call
         
     | 
| 
       168 
     | 
    
         
            -
                      name.start_with?("::") ? name : "::#{name}"
         
     | 
| 
      
 156 
     | 
    
         
            +
                      type
         
     | 
| 
       169 
157 
     | 
    
         
             
                    end
         
     | 
| 
       170 
158 
     | 
    
         
             
                  end
         
     | 
| 
       171 
159 
     | 
    
         
             
                end
         
     | 
| 
         @@ -1,9 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # typed: strict
         
     | 
| 
       2 
2 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
            require "parlour"
         
     | 
| 
       5 
     | 
    
         
            -
            require "tapioca/core_ext/class"
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
4 
     | 
    
         
             
            begin
         
     | 
| 
       8 
5 
     | 
    
         
             
              require "state_machines"
         
     | 
| 
       9 
6 
     | 
    
         
             
            rescue LoadError
         
     | 
| 
         @@ -121,16 +118,19 @@ module Tapioca 
     | 
|
| 
       121 
118 
     | 
    
         
             
                  class StateMachines < Base
         
     | 
| 
       122 
119 
     | 
    
         
             
                    extend T::Sig
         
     | 
| 
       123 
120 
     | 
    
         | 
| 
       124 
     | 
    
         
            -
                    sig { override.params(root:  
     | 
| 
      
 121 
     | 
    
         
            +
                    sig { override.params(root: RBI::Tree, constant: ::StateMachines::ClassMethods).void }
         
     | 
| 
       125 
122 
     | 
    
         
             
                    def decorate(root, constant)
         
     | 
| 
       126 
123 
     | 
    
         
             
                      return if constant.state_machines.empty?
         
     | 
| 
       127 
124 
     | 
    
         | 
| 
       128 
     | 
    
         
            -
                      root. 
     | 
| 
      
 125 
     | 
    
         
            +
                      root.create_path(T.unsafe(constant)) do |klass|
         
     | 
| 
       129 
126 
     | 
    
         
             
                        instance_module_name = "StateMachineInstanceHelperModule"
         
     | 
| 
       130 
127 
     | 
    
         
             
                        class_module_name = "StateMachineClassHelperModule"
         
     | 
| 
       131 
128 
     | 
    
         | 
| 
       132 
     | 
    
         
            -
                        instance_module =  
     | 
| 
       133 
     | 
    
         
            -
                         
     | 
| 
      
 129 
     | 
    
         
            +
                        instance_module = RBI::Module.new(instance_module_name)
         
     | 
| 
      
 130 
     | 
    
         
            +
                        klass << instance_module
         
     | 
| 
      
 131 
     | 
    
         
            +
             
     | 
| 
      
 132 
     | 
    
         
            +
                        class_module = RBI::Module.new(class_module_name)
         
     | 
| 
      
 133 
     | 
    
         
            +
                        klass << class_module
         
     | 
| 
       134 
134 
     | 
    
         | 
| 
       135 
135 
     | 
    
         
             
                        constant.state_machines.each_value do |machine|
         
     | 
| 
       136 
136 
     | 
    
         
             
                          state_type = state_type_for(machine)
         
     | 
| 
         @@ -160,7 +160,7 @@ module Tapioca 
     | 
|
| 
       160 
160 
     | 
    
         | 
| 
       161 
161 
     | 
    
         
             
                    sig { override.returns(T::Enumerable[Module]) }
         
     | 
| 
       162 
162 
     | 
    
         
             
                    def gather_constants
         
     | 
| 
       163 
     | 
    
         
            -
                       
     | 
| 
      
 163 
     | 
    
         
            +
                      all_classes.select { |mod| mod < ::StateMachines::InstanceMethods }
         
     | 
| 
       164 
164 
     | 
    
         
             
                    end
         
     | 
| 
       165 
165 
     | 
    
         | 
| 
       166 
166 
     | 
    
         
             
                    private
         
     | 
| 
         @@ -172,54 +172,48 @@ module Tapioca 
     | 
|
| 
       172 
172 
     | 
    
         
             
                      if value_types.size == 1
         
     | 
| 
       173 
173 
     | 
    
         
             
                        value_types.first
         
     | 
| 
       174 
174 
     | 
    
         
             
                      else
         
     | 
| 
       175 
     | 
    
         
            -
                        "T.any(#{value_types.join( 
     | 
| 
      
 175 
     | 
    
         
            +
                        "T.any(#{value_types.join(", ")})"
         
     | 
| 
       176 
176 
     | 
    
         
             
                      end
         
     | 
| 
       177 
177 
     | 
    
         
             
                    end
         
     | 
| 
       178 
178 
     | 
    
         | 
| 
       179 
     | 
    
         
            -
                    sig { params(instance_module:  
     | 
| 
      
 179 
     | 
    
         
            +
                    sig { params(instance_module: RBI::Module).void }
         
     | 
| 
       180 
180 
     | 
    
         
             
                    def define_activerecord_methods(instance_module)
         
     | 
| 
       181 
     | 
    
         
            -
                      create_method(
         
     | 
| 
       182 
     | 
    
         
            -
                        instance_module,
         
     | 
| 
      
 181 
     | 
    
         
            +
                      instance_module.create_method(
         
     | 
| 
       183 
182 
     | 
    
         
             
                        "changed_for_autosave?",
         
     | 
| 
       184 
183 
     | 
    
         
             
                        return_type: "T::Boolean"
         
     | 
| 
       185 
184 
     | 
    
         
             
                      )
         
     | 
| 
       186 
185 
     | 
    
         
             
                    end
         
     | 
| 
       187 
186 
     | 
    
         | 
| 
       188 
     | 
    
         
            -
                    sig { params(instance_module:  
     | 
| 
      
 187 
     | 
    
         
            +
                    sig { params(instance_module: RBI::Module, machine: ::StateMachines::Machine).void }
         
     | 
| 
       189 
188 
     | 
    
         
             
                    def define_state_methods(instance_module, machine)
         
     | 
| 
       190 
189 
     | 
    
         
             
                      machine.states.each do |state|
         
     | 
| 
       191 
     | 
    
         
            -
                        create_method(
         
     | 
| 
       192 
     | 
    
         
            -
                          instance_module,
         
     | 
| 
      
 190 
     | 
    
         
            +
                        instance_module.create_method(
         
     | 
| 
       193 
191 
     | 
    
         
             
                          "#{state.qualified_name}?",
         
     | 
| 
       194 
192 
     | 
    
         
             
                          return_type: "T::Boolean"
         
     | 
| 
       195 
193 
     | 
    
         
             
                        )
         
     | 
| 
       196 
194 
     | 
    
         
             
                      end
         
     | 
| 
       197 
195 
     | 
    
         
             
                    end
         
     | 
| 
       198 
196 
     | 
    
         | 
| 
       199 
     | 
    
         
            -
                    sig { params(instance_module:  
     | 
| 
      
 197 
     | 
    
         
            +
                    sig { params(instance_module: RBI::Module, machine: ::StateMachines::Machine).void }
         
     | 
| 
       200 
198 
     | 
    
         
             
                    def define_event_methods(instance_module, machine)
         
     | 
| 
       201 
199 
     | 
    
         
             
                      machine.events.each do |event|
         
     | 
| 
       202 
     | 
    
         
            -
                        create_method(
         
     | 
| 
       203 
     | 
    
         
            -
                          instance_module,
         
     | 
| 
      
 200 
     | 
    
         
            +
                        instance_module.create_method(
         
     | 
| 
       204 
201 
     | 
    
         
             
                          "can_#{event.qualified_name}?",
         
     | 
| 
       205 
202 
     | 
    
         
             
                          return_type: "T::Boolean"
         
     | 
| 
       206 
203 
     | 
    
         
             
                        )
         
     | 
| 
       207 
     | 
    
         
            -
                        create_method(
         
     | 
| 
       208 
     | 
    
         
            -
                          instance_module,
         
     | 
| 
      
 204 
     | 
    
         
            +
                        instance_module.create_method(
         
     | 
| 
       209 
205 
     | 
    
         
             
                          "#{event.qualified_name}_transition",
         
     | 
| 
       210 
     | 
    
         
            -
                          parameters: [ 
     | 
| 
      
 206 
     | 
    
         
            +
                          parameters: [create_rest_param("args", type: "T.untyped")],
         
     | 
| 
       211 
207 
     | 
    
         
             
                          return_type: "T.nilable(::StateMachines::Transition)"
         
     | 
| 
       212 
208 
     | 
    
         
             
                        )
         
     | 
| 
       213 
     | 
    
         
            -
                        create_method(
         
     | 
| 
       214 
     | 
    
         
            -
                          instance_module,
         
     | 
| 
      
 209 
     | 
    
         
            +
                        instance_module.create_method(
         
     | 
| 
       215 
210 
     | 
    
         
             
                          event.qualified_name.to_s,
         
     | 
| 
       216 
     | 
    
         
            -
                          parameters: [ 
     | 
| 
      
 211 
     | 
    
         
            +
                          parameters: [create_rest_param("args", type: "T.untyped")],
         
     | 
| 
       217 
212 
     | 
    
         
             
                          return_type: "T::Boolean"
         
     | 
| 
       218 
213 
     | 
    
         
             
                        )
         
     | 
| 
       219 
     | 
    
         
            -
                        create_method(
         
     | 
| 
       220 
     | 
    
         
            -
                          instance_module,
         
     | 
| 
      
 214 
     | 
    
         
            +
                        instance_module.create_method(
         
     | 
| 
       221 
215 
     | 
    
         
             
                          "#{event.qualified_name}!",
         
     | 
| 
       222 
     | 
    
         
            -
                          parameters: [ 
     | 
| 
      
 216 
     | 
    
         
            +
                          parameters: [create_rest_param("args", type: "T.untyped")],
         
     | 
| 
       223 
217 
     | 
    
         
             
                          return_type: "T::Boolean"
         
     | 
| 
       224 
218 
     | 
    
         
             
                        )
         
     | 
| 
       225 
219 
     | 
    
         
             
                      end
         
     | 
| 
         @@ -227,106 +221,95 @@ module Tapioca 
     | 
|
| 
       227 
221 
     | 
    
         | 
| 
       228 
222 
     | 
    
         
             
                    sig do
         
     | 
| 
       229 
223 
     | 
    
         
             
                      params(
         
     | 
| 
       230 
     | 
    
         
            -
                        instance_module:  
     | 
| 
      
 224 
     | 
    
         
            +
                        instance_module: RBI::Module,
         
     | 
| 
       231 
225 
     | 
    
         
             
                        machine: ::StateMachines::Machine,
         
     | 
| 
       232 
226 
     | 
    
         
             
                        state_type: String
         
     | 
| 
       233 
227 
     | 
    
         
             
                      ).void
         
     | 
| 
       234 
228 
     | 
    
         
             
                    end
         
     | 
| 
       235 
229 
     | 
    
         
             
                    def define_state_accessor(instance_module, machine, state_type)
         
     | 
| 
       236 
230 
     | 
    
         
             
                      attribute = machine.attribute.to_s
         
     | 
| 
       237 
     | 
    
         
            -
                      create_method(
         
     | 
| 
       238 
     | 
    
         
            -
                        instance_module,
         
     | 
| 
      
 231 
     | 
    
         
            +
                      instance_module.create_method(
         
     | 
| 
       239 
232 
     | 
    
         
             
                        attribute,
         
     | 
| 
       240 
233 
     | 
    
         
             
                        return_type: state_type
         
     | 
| 
       241 
234 
     | 
    
         
             
                      )
         
     | 
| 
       242 
     | 
    
         
            -
                      create_method(
         
     | 
| 
       243 
     | 
    
         
            -
                        instance_module,
         
     | 
| 
      
 235 
     | 
    
         
            +
                      instance_module.create_method(
         
     | 
| 
       244 
236 
     | 
    
         
             
                        "#{attribute}=",
         
     | 
| 
       245 
     | 
    
         
            -
                        parameters: [ 
     | 
| 
      
 237 
     | 
    
         
            +
                        parameters: [create_param("value", type: state_type)],
         
     | 
| 
       246 
238 
     | 
    
         
             
                        return_type: state_type
         
     | 
| 
       247 
239 
     | 
    
         
             
                      )
         
     | 
| 
       248 
240 
     | 
    
         
             
                    end
         
     | 
| 
       249 
241 
     | 
    
         | 
| 
       250 
     | 
    
         
            -
                    sig { params(instance_module:  
     | 
| 
      
 242 
     | 
    
         
            +
                    sig { params(instance_module: RBI::Module, machine: ::StateMachines::Machine).void }
         
     | 
| 
       251 
243 
     | 
    
         
             
                    def define_state_predicate(instance_module, machine)
         
     | 
| 
       252 
     | 
    
         
            -
                      create_method(
         
     | 
| 
       253 
     | 
    
         
            -
                        instance_module,
         
     | 
| 
      
 244 
     | 
    
         
            +
                      instance_module.create_method(
         
     | 
| 
       254 
245 
     | 
    
         
             
                        "#{machine.name}?",
         
     | 
| 
       255 
     | 
    
         
            -
                        parameters: [ 
     | 
| 
      
 246 
     | 
    
         
            +
                        parameters: [create_param("state", type: "T.any(String, Symbol)")],
         
     | 
| 
       256 
247 
     | 
    
         
             
                        return_type: "T::Boolean"
         
     | 
| 
       257 
248 
     | 
    
         
             
                      )
         
     | 
| 
       258 
249 
     | 
    
         
             
                    end
         
     | 
| 
       259 
250 
     | 
    
         | 
| 
       260 
     | 
    
         
            -
                    sig { params(instance_module:  
     | 
| 
      
 251 
     | 
    
         
            +
                    sig { params(instance_module: RBI::Module, machine: ::StateMachines::Machine).void }
         
     | 
| 
       261 
252 
     | 
    
         
             
                    def define_event_helpers(instance_module, machine)
         
     | 
| 
       262 
253 
     | 
    
         
             
                      events_attribute = machine.attribute(:events).to_s
         
     | 
| 
       263 
254 
     | 
    
         
             
                      transitions_attribute = machine.attribute(:transitions).to_s
         
     | 
| 
       264 
255 
     | 
    
         
             
                      event_attribute = machine.attribute(:event).to_s
         
     | 
| 
       265 
256 
     | 
    
         
             
                      event_transition_attribute = machine.attribute(:event_transition).to_s
         
     | 
| 
       266 
257 
     | 
    
         | 
| 
       267 
     | 
    
         
            -
                      create_method(
         
     | 
| 
       268 
     | 
    
         
            -
                        instance_module,
         
     | 
| 
      
 258 
     | 
    
         
            +
                      instance_module.create_method(
         
     | 
| 
       269 
259 
     | 
    
         
             
                        events_attribute,
         
     | 
| 
       270 
     | 
    
         
            -
                        parameters: [ 
     | 
| 
      
 260 
     | 
    
         
            +
                        parameters: [create_rest_param("args", type: "T.untyped")],
         
     | 
| 
       271 
261 
     | 
    
         
             
                        return_type: "T::Array[T.any(String, Symbol)]"
         
     | 
| 
       272 
262 
     | 
    
         
             
                      )
         
     | 
| 
       273 
     | 
    
         
            -
                      create_method(
         
     | 
| 
       274 
     | 
    
         
            -
                        instance_module,
         
     | 
| 
      
 263 
     | 
    
         
            +
                      instance_module.create_method(
         
     | 
| 
       275 
264 
     | 
    
         
             
                        transitions_attribute,
         
     | 
| 
       276 
     | 
    
         
            -
                        parameters: [ 
     | 
| 
      
 265 
     | 
    
         
            +
                        parameters: [create_rest_param("args", type: "T.untyped")],
         
     | 
| 
       277 
266 
     | 
    
         
             
                        return_type: "T::Array[::StateMachines::Transition]"
         
     | 
| 
       278 
267 
     | 
    
         
             
                      )
         
     | 
| 
       279 
     | 
    
         
            -
                      create_method(
         
     | 
| 
       280 
     | 
    
         
            -
                        instance_module,
         
     | 
| 
      
 268 
     | 
    
         
            +
                      instance_module.create_method(
         
     | 
| 
       281 
269 
     | 
    
         
             
                        "fire_#{event_attribute}",
         
     | 
| 
       282 
270 
     | 
    
         
             
                        parameters: [
         
     | 
| 
       283 
     | 
    
         
            -
                           
     | 
| 
       284 
     | 
    
         
            -
                           
     | 
| 
      
 271 
     | 
    
         
            +
                          create_param("event", type: "T.any(String, Symbol)"),
         
     | 
| 
      
 272 
     | 
    
         
            +
                          create_rest_param("args", type: "T.untyped"),
         
     | 
| 
       285 
273 
     | 
    
         
             
                        ],
         
     | 
| 
       286 
274 
     | 
    
         
             
                        return_type: "T::Boolean"
         
     | 
| 
       287 
275 
     | 
    
         
             
                      )
         
     | 
| 
       288 
276 
     | 
    
         
             
                      if machine.action
         
     | 
| 
       289 
     | 
    
         
            -
                        create_method(
         
     | 
| 
       290 
     | 
    
         
            -
                          instance_module,
         
     | 
| 
      
 277 
     | 
    
         
            +
                        instance_module.create_method(
         
     | 
| 
       291 
278 
     | 
    
         
             
                          event_attribute,
         
     | 
| 
       292 
279 
     | 
    
         
             
                          return_type: "T.nilable(Symbol)"
         
     | 
| 
       293 
280 
     | 
    
         
             
                        )
         
     | 
| 
       294 
     | 
    
         
            -
                        create_method(
         
     | 
| 
       295 
     | 
    
         
            -
                          instance_module,
         
     | 
| 
      
 281 
     | 
    
         
            +
                        instance_module.create_method(
         
     | 
| 
       296 
282 
     | 
    
         
             
                          "#{event_attribute}=",
         
     | 
| 
       297 
     | 
    
         
            -
                          parameters: [ 
     | 
| 
      
 283 
     | 
    
         
            +
                          parameters: [create_param("value", type: "T.any(String, Symbol)")],
         
     | 
| 
       298 
284 
     | 
    
         
             
                          return_type: "T.any(String, Symbol)"
         
     | 
| 
       299 
285 
     | 
    
         
             
                        )
         
     | 
| 
       300 
     | 
    
         
            -
                        create_method(
         
     | 
| 
       301 
     | 
    
         
            -
                          instance_module,
         
     | 
| 
      
 286 
     | 
    
         
            +
                        instance_module.create_method(
         
     | 
| 
       302 
287 
     | 
    
         
             
                          event_transition_attribute,
         
     | 
| 
       303 
288 
     | 
    
         
             
                          return_type: "T.nilable(::StateMachines::Transition)"
         
     | 
| 
       304 
289 
     | 
    
         
             
                        )
         
     | 
| 
       305 
     | 
    
         
            -
                        create_method(
         
     | 
| 
       306 
     | 
    
         
            -
                          instance_module,
         
     | 
| 
      
 290 
     | 
    
         
            +
                        instance_module.create_method(
         
     | 
| 
       307 
291 
     | 
    
         
             
                          "#{event_transition_attribute}=",
         
     | 
| 
       308 
     | 
    
         
            -
                          parameters: [ 
     | 
| 
      
 292 
     | 
    
         
            +
                          parameters: [create_param("value", type: "::StateMachines::Transition")],
         
     | 
| 
       309 
293 
     | 
    
         
             
                          return_type: "::StateMachines::Transition"
         
     | 
| 
       310 
294 
     | 
    
         
             
                        )
         
     | 
| 
       311 
295 
     | 
    
         
             
                      end
         
     | 
| 
       312 
296 
     | 
    
         
             
                    end
         
     | 
| 
       313 
297 
     | 
    
         | 
| 
       314 
     | 
    
         
            -
                    sig { params(instance_module:  
     | 
| 
      
 298 
     | 
    
         
            +
                    sig { params(instance_module: RBI::Module, machine: ::StateMachines::Machine).void }
         
     | 
| 
       315 
299 
     | 
    
         
             
                    def define_path_helpers(instance_module, machine)
         
     | 
| 
       316 
300 
     | 
    
         
             
                      paths_attribute = machine.attribute(:paths).to_s
         
     | 
| 
       317 
301 
     | 
    
         | 
| 
       318 
     | 
    
         
            -
                      create_method(
         
     | 
| 
       319 
     | 
    
         
            -
                        instance_module,
         
     | 
| 
      
 302 
     | 
    
         
            +
                      instance_module.create_method(
         
     | 
| 
       320 
303 
     | 
    
         
             
                        paths_attribute,
         
     | 
| 
       321 
     | 
    
         
            -
                        parameters: [ 
     | 
| 
      
 304 
     | 
    
         
            +
                        parameters: [create_rest_param("args", type: "T.untyped")],
         
     | 
| 
       322 
305 
     | 
    
         
             
                        return_type: "T::Array[::StateMachines::Transition]"
         
     | 
| 
       323 
306 
     | 
    
         
             
                      )
         
     | 
| 
       324 
307 
     | 
    
         
             
                    end
         
     | 
| 
       325 
308 
     | 
    
         | 
| 
       326 
309 
     | 
    
         
             
                    sig do
         
     | 
| 
       327 
310 
     | 
    
         
             
                      params(
         
     | 
| 
       328 
     | 
    
         
            -
                        instance_module:  
     | 
| 
       329 
     | 
    
         
            -
                        class_module:  
     | 
| 
      
 311 
     | 
    
         
            +
                        instance_module: RBI::Module,
         
     | 
| 
      
 312 
     | 
    
         
            +
                        class_module: RBI::Module,
         
     | 
| 
       330 
313 
     | 
    
         
             
                        machine: ::StateMachines::Machine
         
     | 
| 
       331 
314 
     | 
    
         
             
                      ).void
         
     | 
| 
       332 
315 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -334,31 +317,27 @@ module Tapioca 
     | 
|
| 
       334 
317 
     | 
    
         
             
                      name_attribute = machine.attribute(:name).to_s
         
     | 
| 
       335 
318 
     | 
    
         
             
                      event_name_attribute = machine.attribute(:event_name).to_s
         
     | 
| 
       336 
319 
     | 
    
         | 
| 
       337 
     | 
    
         
            -
                      create_method(
         
     | 
| 
       338 
     | 
    
         
            -
                        class_module,
         
     | 
| 
      
 320 
     | 
    
         
            +
                      class_module.create_method(
         
     | 
| 
       339 
321 
     | 
    
         
             
                        "human_#{name_attribute}",
         
     | 
| 
       340 
     | 
    
         
            -
                        parameters: [ 
     | 
| 
      
 322 
     | 
    
         
            +
                        parameters: [create_param("state", type: "T.any(String, Symbol)")],
         
     | 
| 
       341 
323 
     | 
    
         
             
                        return_type: "String"
         
     | 
| 
       342 
324 
     | 
    
         
             
                      )
         
     | 
| 
       343 
     | 
    
         
            -
                      create_method(
         
     | 
| 
       344 
     | 
    
         
            -
                        class_module,
         
     | 
| 
      
 325 
     | 
    
         
            +
                      class_module.create_method(
         
     | 
| 
       345 
326 
     | 
    
         
             
                        "human_#{event_name_attribute}",
         
     | 
| 
       346 
     | 
    
         
            -
                        parameters: [ 
     | 
| 
      
 327 
     | 
    
         
            +
                        parameters: [create_param("event", type: "T.any(String, Symbol)")],
         
     | 
| 
       347 
328 
     | 
    
         
             
                        return_type: "String"
         
     | 
| 
       348 
329 
     | 
    
         
             
                      )
         
     | 
| 
       349 
     | 
    
         
            -
                      create_method(
         
     | 
| 
       350 
     | 
    
         
            -
                        instance_module,
         
     | 
| 
      
 330 
     | 
    
         
            +
                      instance_module.create_method(
         
     | 
| 
       351 
331 
     | 
    
         
             
                        name_attribute,
         
     | 
| 
       352 
332 
     | 
    
         
             
                        return_type: "T.any(String, Symbol)"
         
     | 
| 
       353 
333 
     | 
    
         
             
                      )
         
     | 
| 
       354 
     | 
    
         
            -
                      create_method(
         
     | 
| 
       355 
     | 
    
         
            -
                        instance_module,
         
     | 
| 
      
 334 
     | 
    
         
            +
                      instance_module.create_method(
         
     | 
| 
       356 
335 
     | 
    
         
             
                        "human_#{name_attribute}",
         
     | 
| 
       357 
336 
     | 
    
         
             
                        return_type: "String"
         
     | 
| 
       358 
337 
     | 
    
         
             
                      )
         
     | 
| 
       359 
338 
     | 
    
         
             
                    end
         
     | 
| 
       360 
339 
     | 
    
         | 
| 
       361 
     | 
    
         
            -
                    sig { params(class_module:  
     | 
| 
      
 340 
     | 
    
         
            +
                    sig { params(class_module: RBI::Module, machine: ::StateMachines::Machine).void }
         
     | 
| 
       362 
341 
     | 
    
         
             
                    def define_scopes(class_module, machine)
         
     | 
| 
       363 
342 
     | 
    
         
             
                      helper_modules = machine.instance_variable_get(:@helper_modules)
         
     | 
| 
       364 
343 
     | 
    
         
             
                      class_methods = helper_modules[:class].instance_methods(false)
         
     | 
| 
         @@ -366,10 +345,9 @@ module Tapioca 
     | 
|
| 
       366 
345 
     | 
    
         
             
                      class_methods
         
     | 
| 
       367 
346 
     | 
    
         
             
                        .select { |method| method.to_s.start_with?("with_", "without_") }
         
     | 
| 
       368 
347 
     | 
    
         
             
                        .each do |method|
         
     | 
| 
       369 
     | 
    
         
            -
                          create_method(
         
     | 
| 
       370 
     | 
    
         
            -
                            class_module,
         
     | 
| 
      
 348 
     | 
    
         
            +
                          class_module.create_method(
         
     | 
| 
       371 
349 
     | 
    
         
             
                            method.to_s,
         
     | 
| 
       372 
     | 
    
         
            -
                            parameters: [ 
     | 
| 
      
 350 
     | 
    
         
            +
                            parameters: [create_rest_param("states", type: "T.any(String, Symbol)")],
         
     | 
| 
       373 
351 
     | 
    
         
             
                            return_type: "T.untyped"
         
     | 
| 
       374 
352 
     | 
    
         
             
                          )
         
     | 
| 
       375 
353 
     | 
    
         
             
                        end
         
     | 
| 
         @@ -1,8 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # typed: strict
         
     | 
| 
       2 
2 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
            require "parlour"
         
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
4 
     | 
    
         
             
            begin
         
     | 
| 
       7 
5 
     | 
    
         
             
              require "rails"
         
     | 
| 
       8 
6 
     | 
    
         
             
              require "action_controller"
         
     | 
| 
         @@ -89,13 +87,13 @@ module Tapioca 
     | 
|
| 
       89 
87 
     | 
    
         
             
                  class UrlHelpers < Base
         
     | 
| 
       90 
88 
     | 
    
         
             
                    extend T::Sig
         
     | 
| 
       91 
89 
     | 
    
         | 
| 
       92 
     | 
    
         
            -
                    sig { override.params(root:  
     | 
| 
      
 90 
     | 
    
         
            +
                    sig { override.params(root: RBI::Tree, constant: Module).void }
         
     | 
| 
       93 
91 
     | 
    
         
             
                    def decorate(root, constant)
         
     | 
| 
       94 
92 
     | 
    
         
             
                      case constant
         
     | 
| 
       95 
93 
     | 
    
         
             
                      when GeneratedPathHelpersModule.singleton_class, GeneratedUrlHelpersModule.singleton_class
         
     | 
| 
       96 
94 
     | 
    
         
             
                        generate_module_for(root, constant)
         
     | 
| 
       97 
95 
     | 
    
         
             
                      else
         
     | 
| 
       98 
     | 
    
         
            -
                        root. 
     | 
| 
      
 96 
     | 
    
         
            +
                        root.create_path(constant) do |mod|
         
     | 
| 
       99 
97 
     | 
    
         
             
                          create_mixins_for(mod, constant, GeneratedUrlHelpersModule)
         
     | 
| 
       100 
98 
     | 
    
         
             
                          create_mixins_for(mod, constant, GeneratedPathHelpersModule)
         
     | 
| 
       101 
99 
     | 
    
         
             
                        end
         
     | 
| 
         @@ -112,9 +110,8 @@ module Tapioca 
     | 
|
| 
       112 
110 
     | 
    
         
             
                      Object.const_set(:GeneratedUrlHelpersModule, Rails.application.routes.named_routes.url_helpers_module)
         
     | 
| 
       113 
111 
     | 
    
         
             
                      Object.const_set(:GeneratedPathHelpersModule, Rails.application.routes.named_routes.path_helpers_module)
         
     | 
| 
       114 
112 
     | 
    
         | 
| 
       115 
     | 
    
         
            -
                       
     | 
| 
       116 
     | 
    
         
            -
             
     | 
| 
       117 
     | 
    
         
            -
                        next unless Module.instance_method(:name).bind(mod).call
         
     | 
| 
      
 113 
     | 
    
         
            +
                      constants = all_modules.select do |mod|
         
     | 
| 
      
 114 
     | 
    
         
            +
                        next unless name_of(mod)
         
     | 
| 
       118 
115 
     | 
    
         | 
| 
       119 
116 
     | 
    
         
             
                        includes_helper?(mod, GeneratedUrlHelpersModule) ||
         
     | 
| 
       120 
117 
     | 
    
         
             
                          includes_helper?(mod, GeneratedPathHelpersModule) ||
         
     | 
| 
         @@ -127,7 +124,7 @@ module Tapioca 
     | 
|
| 
       127 
124 
     | 
    
         | 
| 
       128 
125 
     | 
    
         
             
                    private
         
     | 
| 
       129 
126 
     | 
    
         | 
| 
       130 
     | 
    
         
            -
                    sig { params(root:  
     | 
| 
      
 127 
     | 
    
         
            +
                    sig { params(root: RBI::Tree, constant: Module).void }
         
     | 
| 
       131 
128 
     | 
    
         
             
                    def generate_module_for(root, constant)
         
     | 
| 
       132 
129 
     | 
    
         
             
                      root.create_module(T.must(constant.name)) do |mod|
         
     | 
| 
       133 
130 
     | 
    
         
             
                        mod.create_include("::ActionDispatch::Routing::UrlFor")
         
     | 
| 
         @@ -136,14 +133,14 @@ module Tapioca 
     | 
|
| 
       136 
133 
     | 
    
         
             
                        constant.instance_methods(false).each do |method|
         
     | 
| 
       137 
134 
     | 
    
         
             
                          mod.create_method(
         
     | 
| 
       138 
135 
     | 
    
         
             
                            method.to_s,
         
     | 
| 
       139 
     | 
    
         
            -
                            parameters: [ 
     | 
| 
      
 136 
     | 
    
         
            +
                            parameters: [create_rest_param("args", type: "T.untyped")],
         
     | 
| 
       140 
137 
     | 
    
         
             
                            return_type: "String"
         
     | 
| 
       141 
138 
     | 
    
         
             
                          )
         
     | 
| 
       142 
139 
     | 
    
         
             
                        end
         
     | 
| 
       143 
140 
     | 
    
         
             
                      end
         
     | 
| 
       144 
141 
     | 
    
         
             
                    end
         
     | 
| 
       145 
142 
     | 
    
         | 
| 
       146 
     | 
    
         
            -
                    sig { params(mod:  
     | 
| 
      
 143 
     | 
    
         
            +
                    sig { params(mod: RBI::Scope, constant: Module, helper_module: Module).void }
         
     | 
| 
       147 
144 
     | 
    
         
             
                    def create_mixins_for(mod, constant, helper_module)
         
     | 
| 
       148 
145 
     | 
    
         
             
                      include_helper = constant.ancestors.include?(helper_module) || NON_DISCOVERABLE_INCLUDERS.include?(constant)
         
     | 
| 
       149 
146 
     | 
    
         
             
                      extend_helper = constant.singleton_class.ancestors.include?(helper_module)
         
     |