1
- Rails . configuration . autoloader = :classic #:zeitwerk
1
+ # require "hyperstack/server_side_auto_require.rb" in your hyperstack initializer
2
+ # to autoload shadowed server side files that match files
3
+ # in the hyperstack directory
4
+
5
+ if Rails . configuration . try ( :autoloader ) == :zeitwerk
6
+ Rails . autoloaders . each do |loader |
7
+ loader . on_load do |_cpath , _value , abspath |
8
+ ActiveSupport ::Dependencies . add_server_side_dependency ( abspath ) do |load_path |
9
+ loader . send ( :log , "Hyperstack loading server side shadowed file: #{ load_path } " ) if loader &.logger
10
+ require ( "#{ load_path } .rb" )
11
+ end
12
+ end
13
+ end
14
+ end
2
15
3
16
module ActiveSupport
4
17
module Dependencies
@@ -11,7 +24,7 @@ class << self
11
24
# and add that as a dependency
12
25
13
26
def require_or_load ( file_name , const_path = nil )
14
- add_server_side_dependency ( file_name )
27
+ add_server_side_dependency ( file_name ) { | load_path | require_dependency load_path }
15
28
original_require_or_load ( file_name , const_path )
16
29
end
17
30
@@ -20,7 +33,7 @@ def require_or_load(file_name, const_path = nil)
20
33
# the filename, and if a ruby file exists at that location then
21
34
# add it as a dependency
22
35
23
- def add_server_side_dependency ( file_name )
36
+ def add_server_side_dependency ( file_name , loader = nil )
24
37
path = File . expand_path ( file_name . chomp ( ".rb" ) )
25
38
. split ( File ::SEPARATOR ) . reverse
26
39
hs_index = path . find_index ( HYPERSTACK_DIR )
@@ -32,7 +45,7 @@ def add_server_side_dependency(file_name)
32
45
33
46
return unless File . exist? "#{ load_path } .rb"
34
47
35
- require_dependency load_path
48
+ yield load_path
36
49
end
37
50
end
38
51
end
0 commit comments