-
Notifications
You must be signed in to change notification settings - Fork 21.4k
/
route_set.rb
54 lines (45 loc) · 1.53 KB
/
route_set.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# frozen_string_literal: true
# :markup: markdown
require "action_dispatch/routing/route_set"
module Rails
class Engine
class RouteSet < ActionDispatch::Routing::RouteSet # :nodoc:
class NamedRouteCollection < ActionDispatch::Routing::RouteSet::NamedRouteCollection
def route_defined?(name)
Rails.application&.reload_routes_unless_loaded
super(name)
end
end
def initialize(config = DEFAULT_CONFIG)
super
self.named_routes = NamedRouteCollection.new
named_routes.url_helpers_module.prepend(method_missing_module)
named_routes.path_helpers_module.prepend(method_missing_module)
end
def generate_extras(options, recall = {})
Rails.application&.reload_routes_unless_loaded
super(options, recall)
end
private
def method_missing_module
@method_missing_module ||= Module.new do
private
def method_missing(method_name, *args, &block)
if Rails.application&.reload_routes_unless_loaded
public_send(method_name, *args, &block)
else
super(method_name, *args, &block)
end
end
def respond_to_missing?(method_name, *args)
if Rails.application&.reload_routes_unless_loaded
respond_to?(method_name, *args)
else
super(method_name, *args)
end
end
end
end
end
end
end