sorbet_view 0.16.1 → 0.17.0
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/lib/sorbet_view/version.rb +1 -1
- data/lib/tapioca/dsl/compilers/sorbet_view.rb +42 -8
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 330016607634f904162184802a0fb8efa933da90179b192b1e3113a296ccf113
|
|
4
|
+
data.tar.gz: 1770334f364c5eae2b56ffe15ce222f157cc8eb7c53a94e371f8d4103a91a8fb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f2381a372dc8ebb770e7e73e978a2af499d1e83ea2664a55d4e9657b0a7296118edbaa5150867a72caa667d0121a21a9da153266377f0f93d1d167a0409efefc
|
|
7
|
+
data.tar.gz: 185f3fed2527ddc2a7011550c0d1a2b7a21872164949ddbd5a74fee9627fa7fc1397e7bf80ba4477e1b20626cbd320c123dc83a5e5a6e6a0848c32f41319538c
|
data/lib/sorbet_view/version.rb
CHANGED
|
@@ -28,6 +28,9 @@ module Tapioca
|
|
|
28
28
|
@module_cache = T.let({}, T::Hash[String, RBI::Scope])
|
|
29
29
|
@project = T.let(SrbLens::Project.load_or_index(Dir.pwd), T.untyped)
|
|
30
30
|
|
|
31
|
+
# Ensure all controllers are loaded
|
|
32
|
+
Rails.application.eager_load! if defined?(Rails) && Rails.respond_to?(:application)
|
|
33
|
+
|
|
31
34
|
controllers = ObjectSpace.each_object(Class).select do |klass|
|
|
32
35
|
klass < ::ActionController::Base && !klass.abstract?
|
|
33
36
|
rescue StandardError
|
|
@@ -238,27 +241,34 @@ module Tapioca
|
|
|
238
241
|
sig { params(controller: T.untyped).void }
|
|
239
242
|
def process_controller(controller)
|
|
240
243
|
helper_methods = extract_helper_methods(controller)
|
|
241
|
-
|
|
244
|
+
controller_helper_modules = extract_controller_helper_modules(controller)
|
|
245
|
+
return if helper_methods.empty? && controller_helper_modules.empty?
|
|
242
246
|
|
|
243
247
|
path = controller.controller_path
|
|
244
248
|
parts = path.split('/').map { |p| camelize(p) }
|
|
245
249
|
|
|
246
|
-
# 1) module SorbetView::Helpers::<controller_path> with helper methods
|
|
247
|
-
helper_module_name =
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
250
|
+
# 1) module SorbetView::Helpers::<controller_path> with helper methods from helper_method macro
|
|
251
|
+
helper_module_name = nil
|
|
252
|
+
unless helper_methods.empty?
|
|
253
|
+
helper_module_name = "SorbetView::Helpers::#{parts.join('::')}"
|
|
254
|
+
create_module_from_path(helper_module_name) do |mod|
|
|
255
|
+
helper_methods.each do |method_name, params, return_type|
|
|
256
|
+
mod.create_method(method_name, parameters: params, return_type: return_type)
|
|
257
|
+
end
|
|
251
258
|
end
|
|
252
259
|
end
|
|
253
260
|
|
|
254
|
-
# 2) Each action's template class includes the helper module
|
|
261
|
+
# 2) Each action's template class includes the helper module and controller-specific helper modules
|
|
255
262
|
actions = controller.action_methods.to_a
|
|
256
263
|
actions.each do |action_name|
|
|
257
264
|
next unless action_name.match?(/\A[a-zA-Z_][a-zA-Z0-9_]*\z/)
|
|
258
265
|
|
|
259
266
|
class_name = "SorbetView::Generated::#{parts.join('::')}::#{camelize(action_name)}"
|
|
260
267
|
create_class_from_path(class_name) do |klass|
|
|
261
|
-
klass.create_include(helper_module_name)
|
|
268
|
+
klass.create_include(helper_module_name) if helper_module_name
|
|
269
|
+
controller_helper_modules.each do |mod_name|
|
|
270
|
+
klass.create_include("::#{mod_name}")
|
|
271
|
+
end
|
|
262
272
|
end
|
|
263
273
|
end
|
|
264
274
|
end
|
|
@@ -285,6 +295,30 @@ module Tapioca
|
|
|
285
295
|
end
|
|
286
296
|
end
|
|
287
297
|
|
|
298
|
+
# Returns controller-specific helper module names (modules included via `helper` that are not in ApplicationController)
|
|
299
|
+
sig { params(controller: T.untyped).returns(T::Array[String]) }
|
|
300
|
+
def extract_controller_helper_modules(controller)
|
|
301
|
+
return [] unless controller.respond_to?(:_helpers)
|
|
302
|
+
|
|
303
|
+
base_helpers = if defined?(::ApplicationController) && ::ApplicationController.respond_to?(:_helpers)
|
|
304
|
+
::ApplicationController._helpers.ancestors
|
|
305
|
+
else
|
|
306
|
+
[]
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
controller_helpers = controller._helpers.ancestors
|
|
310
|
+
specific_modules = controller_helpers - base_helpers
|
|
311
|
+
|
|
312
|
+
specific_modules.filter_map do |mod|
|
|
313
|
+
next unless mod.is_a?(Module) && !mod.is_a?(Class)
|
|
314
|
+
name = mod.name
|
|
315
|
+
next if name.nil? || name.empty?
|
|
316
|
+
next if name.include?('HelperMethods')
|
|
317
|
+
next if name.start_with?('ActionController::') || name.start_with?('AbstractController::')
|
|
318
|
+
name
|
|
319
|
+
end
|
|
320
|
+
end
|
|
321
|
+
|
|
288
322
|
sig { params(controller: T.untyped, method_name: String).returns(T.untyped) }
|
|
289
323
|
def find_method_info(controller, method_name)
|
|
290
324
|
methods = @project.find_methods("#{controller.name}##{method_name}")
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sorbet_view
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.17.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- kazuma
|
|
8
8
|
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-04-
|
|
10
|
+
date: 2026-04-04 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: herb
|