|
13 | 13 | require_relative "rfc3986_parser" |
14 | 14 |
|
15 | 15 | module URI |
16 | | - include RFC2396_REGEXP |
| 16 | + RFC2396_PARSER = RFC2396_Parser.new |
| 17 | + Ractor.make_shareable(RFC2396_PARSER) if defined?(Ractor) |
17 | 18 |
|
18 | | - REGEXP = RFC2396_REGEXP |
19 | | - Parser = RFC2396_Parser |
20 | 19 | RFC3986_PARSER = RFC3986_Parser.new |
21 | 20 | Ractor.make_shareable(RFC3986_PARSER) if defined?(Ractor) |
22 | 21 |
|
23 | | - # URI::Parser.new |
24 | | - DEFAULT_PARSER = Parser.new |
25 | | - DEFAULT_PARSER.pattern.each_pair do |sym, str| |
26 | | - unless REGEXP::PATTERN.const_defined?(sym) |
27 | | - REGEXP::PATTERN.const_set(sym, str) |
| 22 | + def self.parser=(parser = RFC3986_PARSER) |
| 23 | + remove_const(:Parser) if defined?(Parser) |
| 24 | + remove_const(:DEFAULT_PARSER) if defined?(DEFAULT_PARSER) |
| 25 | + remove_const(:REGEXP) if defined?(REGEXP) |
| 26 | + |
| 27 | + # URI::Parser.new |
| 28 | + const_set("Parser", parser.class) |
| 29 | + const_set("DEFAULT_PARSER", parser) |
| 30 | + if DEFAULT_PARSER.class == RFC2396_Parser |
| 31 | + const_set("REGEXP", RFC2396_PARSER::REGEXP) |
| 32 | + DEFAULT_PARSER.pattern.each_pair do |sym, str| |
| 33 | + unless REGEXP::PATTERN.const_defined?(sym) |
| 34 | + REGEXP::PATTERN.const_set(sym, str) |
| 35 | + end |
| 36 | + end |
28 | 37 | end |
| 38 | + DEFAULT_PARSER.regexp.each_pair do |sym, str| |
| 39 | + remove_const(sym) if const_defined?(sym) |
| 40 | + const_set(sym, str) |
| 41 | + end |
| 42 | + Ractor.make_shareable(DEFAULT_PARSER) if defined?(Ractor) |
29 | 43 | end |
30 | | - DEFAULT_PARSER.regexp.each_pair do |sym, str| |
31 | | - const_set(sym, str) |
32 | | - end |
33 | | - Ractor.make_shareable(DEFAULT_PARSER) if defined?(Ractor) |
| 44 | + self.parser = RFC3986_PARSER |
34 | 45 |
|
35 | 46 | module Util # :nodoc: |
36 | 47 | def make_components_hash(klass, array_hash) |
|
0 commit comments