Sha256: db4536d322101b2e10d8e801fbf9f18763494947883c0c62607b046555e228f0
Contents?: true
Size: 805 Bytes
Versions: 8
Compression:
Stored size: 805 Bytes
Contents
# frozen_string_literal: true module Rack::App::InstanceMethods::PathTo def path_to(defined_path, options = {}) app_class = options[:class] || self.class query_string_hash = options[:params] || {} options.each do |k, v| k.is_a?(String) && query_string_hash[k] = v end router = request.env[Rack::App::Constants::ENV::ROUTER] final_path = router.path_to(app_class, defined_path) path_keys = final_path.scan(/:(\w+)/).flatten path_keys.each do |key| value = query_string_hash.delete(key) || params[key] || raise("missing path-key value for #{key}!") final_path.gsub!(/:#{key}/, value.to_s) end unless query_string_hash.empty? final_path.concat("?" + Rack::App::Utils.encode_www_form(query_string_hash)) end final_path end end
Version data entries
8 entries across 8 versions & 1 rubygems