Method: Typhoeus::RemoteMethod#compile
- Defined in:
- lib/typhoeus/remote_method.rb
#compile(path) ⇒ Object
rippped from Sinatra. clean up stuff we don’t need later
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/typhoeus/remote_method.rb', line 82 def compile(path) path ||= "" keys = [] if path.respond_to? :to_str special_chars = %w{. + ( )} pattern = path.gsub(/((:\w+)|[\*#{special_chars.join}])/) do |match| case match when "*" keys << 'splat' "(.*?)" when *special_chars Regexp.escape(match) else keys << $2[1..-1] "([^/?&#]+)" end end [/^#{pattern}$/, keys] elsif path.respond_to? :match [path, keys] else raise TypeError, path end end |