Module: RightSpeed::RactorHelper
- Defined in:
- lib/right_speed/ractor_helper.rb
Class Method Summary collapse
- .freeze_all_constants(mojule, touch_list = []) ⇒ Object
- .overwrite_const(mojule, name, value) ⇒ Object
- .overwrite_method(mojule, name, value = nil, &block) ⇒ Object
- .rack_hook ⇒ Object
- .uri_hook ⇒ Object
Class Method Details
.freeze_all_constants(mojule, touch_list = []) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/right_speed/ractor_helper.rb', line 22 def self.freeze_all_constants(mojule, touch_list=[]) touch_list << mojule mojule.constants.each do |const_name| const = begin mojule.const_get(const_name) rescue LoadError # ignore unloadable modules (autoload, probably) nil end next unless const if const.is_a?(Module) && !touch_list.include?(const) # not freeze Module/Class because we're going to do monkey patching... freeze_all_constants(const, touch_list) else const.freeze end end end |
.overwrite_const(mojule, name, value) ⇒ Object
50 51 52 53 |
# File 'lib/right_speed/ractor_helper.rb', line 50 def self.overwrite_const(mojule, name, value) v = Ractor.make_shareable(value) mojule.const_set(name, value) end |
.overwrite_method(mojule, name, value = nil, &block) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/right_speed/ractor_helper.rb', line 41 def self.overwrite_method(mojule, name, value=nil, &block) if block_given? mojule.define_method(name, Ractor.make_shareable(block)) else v = Ractor.make_shareable(value) mojule.define_method(name, Ractor.make_shareable(->(){ v })) end end |
.rack_hook ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/right_speed/ractor_helper.rb', line 12 def self.rack_hook ip_filter = Ractor.make_shareable(Rack::Request.ip_filter) overwrite_method(Rack::Request::Helpers, :trusted_proxy?) do |ip| ip_filter.call(ip) end overwrite_method(Rack::Request::Helpers, :query_parser, Rack::Utils.default_query_parser) overwrite_const(Rack::ShowExceptions, :TEMPLATE, Rack::ShowExceptions::TEMPLATE) freeze_all_constants(::Rack) end |
.uri_hook ⇒ Object
8 9 10 |
# File 'lib/right_speed/ractor_helper.rb', line 8 def self.uri_hook # Use 3.1.0-dev! end |