lib/tapioca/compilers/dsl/url_helpers.rb in tapioca-0.4.27 vs lib/tapioca/compilers/dsl/url_helpers.rb in tapioca-0.5.0
- old
+ new
@@ -1,10 +1,8 @@
# typed: strict
# frozen_string_literal: true
-require "parlour"
-
begin
require "rails"
require "action_controller"
require "action_view"
rescue LoadError
@@ -87,17 +85,17 @@
# end
# ~~~
class UrlHelpers < Base
extend T::Sig
- sig { override.params(root: Parlour::RbiGenerator::Namespace, constant: Module).void }
+ sig { override.params(root: RBI::Tree, constant: Module).void }
def decorate(root, constant)
case constant
when GeneratedPathHelpersModule.singleton_class, GeneratedUrlHelpersModule.singleton_class
generate_module_for(root, constant)
else
- root.path(constant) do |mod|
+ root.create_path(constant) do |mod|
create_mixins_for(mod, constant, GeneratedUrlHelpersModule)
create_mixins_for(mod, constant, GeneratedPathHelpersModule)
end
end
end
@@ -110,13 +108,12 @@
sig { override.returns(T::Enumerable[Module]) }
def gather_constants
Object.const_set(:GeneratedUrlHelpersModule, Rails.application.routes.named_routes.url_helpers_module)
Object.const_set(:GeneratedPathHelpersModule, Rails.application.routes.named_routes.path_helpers_module)
- module_enumerator = T.cast(ObjectSpace.each_object(Module), T::Enumerator[Module])
- constants = module_enumerator.select do |mod|
- next unless Module.instance_method(:name).bind(mod).call
+ constants = all_modules.select do |mod|
+ next unless name_of(mod)
includes_helper?(mod, GeneratedUrlHelpersModule) ||
includes_helper?(mod, GeneratedPathHelpersModule) ||
includes_helper?(mod.singleton_class, GeneratedUrlHelpersModule) ||
includes_helper?(mod.singleton_class, GeneratedPathHelpersModule)
@@ -125,26 +122,26 @@
constants.concat(NON_DISCOVERABLE_INCLUDERS)
end
private
- sig { params(root: Parlour::RbiGenerator::Namespace, constant: Module).void }
+ sig { params(root: RBI::Tree, constant: Module).void }
def generate_module_for(root, constant)
root.create_module(T.must(constant.name)) do |mod|
mod.create_include("::ActionDispatch::Routing::UrlFor")
mod.create_include("::ActionDispatch::Routing::PolymorphicRoutes")
constant.instance_methods(false).each do |method|
mod.create_method(
method.to_s,
- parameters: [Parlour::RbiGenerator::Parameter.new("*args", type: "T.untyped")],
+ parameters: [create_rest_param("args", type: "T.untyped")],
return_type: "String"
)
end
end
end
- sig { params(mod: Parlour::RbiGenerator::Namespace, constant: Module, helper_module: Module).void }
+ sig { params(mod: RBI::Scope, constant: Module, helper_module: Module).void }
def create_mixins_for(mod, constant, helper_module)
include_helper = constant.ancestors.include?(helper_module) || NON_DISCOVERABLE_INCLUDERS.include?(constant)
extend_helper = constant.singleton_class.ancestors.include?(helper_module)
mod.create_include(T.must(helper_module.name)) if include_helper