Class: RactorRailsShim::DeviseMappingSnapshot
- Inherits:
-
Object
- Object
- RactorRailsShim::DeviseMappingSnapshot
show all
- Defined in:
- lib/ractor_rails_shim/patches/callables.rb
Overview
Shareable snapshot of a Devise::Mapping. The real Mapping holds an
unshareable lambda (failure_app) plus a default-proc Hash (controllers),
so it can't be Ractor.make_shareable'd. Request-time code only reads a
handful of attributes (name, to/class, router_name, controllers, ...),
which are all shareable values. We copy those now (in main) into a
frozen Plain Old Object that plays the role of the Mapping in workers.
Instance Method Summary
collapse
Constructor Details
Returns a new instance of DeviseMappingSnapshot.
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/ractor_rails_shim/patches/callables.rb', line 56
def initialize(mapping)
@name = mapping.name
@klass = mapping.to
@router_name = mapping.instance_variable_get(:@router_name)
@singular = mapping.instance_variable_get(:@singular)
@scoped_path = mapping.instance_variable_get(:@scoped_path)
@path = mapping.instance_variable_get(:@path)
@path_prefix = mapping.instance_variable_get(:@path_prefix)
@format = mapping.instance_variable_get(:@format)
@sign_out_via = mapping.instance_variable_get(:@sign_out_via)
@modules = mapping.modules
@strategies = mapping.strategies
@routes = mapping.routes
@used_helpers = mapping.used_helpers
h = {}
RactorRailsShim._swallow("devise mapping controllers") do
mapping.controllers.each { |k, v| h[k] = v }
end
@controllers = h.freeze
fa = mapping.instance_variable_get(:@failure_app)
fa = ::Devise::FailureApp unless fa.is_a?(Class)
@failure_app = fa
freeze
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
111
112
113
114
115
116
117
118
|
# File 'lib/ractor_rails_shim/patches/callables.rb', line 111
def method_missing(method, *args)
s = method.to_s
if s.end_with?("?") && args.empty?
@modules.include?(s.chomp("?").to_sym)
else
super
end
end
|
Instance Method Details
#authenticatable? ⇒ Boolean
100
|
# File 'lib/ractor_rails_shim/patches/callables.rb', line 100
def authenticatable?; @modules.any? { |m| m.to_s =~ /authenticatable/ }; end
|
#controllers ⇒ Object
98
|
# File 'lib/ractor_rails_shim/patches/callables.rb', line 98
def controllers; @controllers; end
|
#failure_app ⇒ Object
99
|
# File 'lib/ractor_rails_shim/patches/callables.rb', line 99
def failure_app; @failure_app; end
|
92
|
# File 'lib/ractor_rails_shim/patches/callables.rb', line 92
def format; @format; end
|
#fullpath ⇒ Object
102
|
# File 'lib/ractor_rails_shim/patches/callables.rb', line 102
def fullpath; "/#{@path_prefix}/#{@path}".squeeze("/"); end
|
#modules ⇒ Object
94
|
# File 'lib/ractor_rails_shim/patches/callables.rb', line 94
def modules; @modules; end
|
#name ⇒ Object
85
|
# File 'lib/ractor_rails_shim/patches/callables.rb', line 85
def name; @name; end
|
101
|
# File 'lib/ractor_rails_shim/patches/callables.rb', line 101
def no_input_strategies; @strategies & Devise::NO_INPUT; end
|
#path ⇒ Object
90
|
# File 'lib/ractor_rails_shim/patches/callables.rb', line 90
def path; @path; end
|
#path_prefix ⇒ Object
91
|
# File 'lib/ractor_rails_shim/patches/callables.rb', line 91
def path_prefix; @path_prefix; end
|
#respond_to_missing?(method, _) ⇒ Boolean
Devise::Mapping defines one x? predicate per Devise module
(confirmable?, rememberable?, registerable?, ...) via add_module.
Rather than enumerate them, fall back for any x? predicate to
checking @modules — matching the generated behaviour.
107
108
109
|
# File 'lib/ractor_rails_shim/patches/callables.rb', line 107
def respond_to_missing?(method, _)
method.to_s.end_with?("?") || super
end
|
#router_name ⇒ Object
87
|
# File 'lib/ractor_rails_shim/patches/callables.rb', line 87
def router_name; @router_name; end
|
#routes ⇒ Object
96
|
# File 'lib/ractor_rails_shim/patches/callables.rb', line 96
def routes; @routes; end
|
#scoped_path ⇒ Object
89
|
# File 'lib/ractor_rails_shim/patches/callables.rb', line 89
def scoped_path; @scoped_path; end
|
#sign_out_via ⇒ Object
93
|
# File 'lib/ractor_rails_shim/patches/callables.rb', line 93
def sign_out_via; @sign_out_via; end
|
#singular ⇒ Object
88
|
# File 'lib/ractor_rails_shim/patches/callables.rb', line 88
def singular; @singular; end
|
#strategies ⇒ Object
95
|
# File 'lib/ractor_rails_shim/patches/callables.rb', line 95
def strategies; @strategies; end
|
#to ⇒ Object
86
|
# File 'lib/ractor_rails_shim/patches/callables.rb', line 86
def to; @klass; end
|
#used_helpers ⇒ Object
97
|
# File 'lib/ractor_rails_shim/patches/callables.rb', line 97
def used_helpers; @used_helpers; end
|