Permalink
Browse files

Move uri parser to AS as URI.parser method to reuse it in AP and ARes.

  • Loading branch information...
1 parent b7934af commit 71acc2737aa346ee57f9fc21252a508ae83367a4 @miloops miloops committed with josevalim Sep 27, 2010
@@ -8,7 +8,6 @@ module ActionController
autoload :Caching
autoload :Metal
autoload :Middleware
- autoload :UriParser
autoload_under "metal" do
autoload :Compatibility
@@ -73,4 +72,5 @@ module ActionController
require 'active_support/core_ext/module/attr_internal'
require 'active_support/core_ext/module/delegation'
require 'active_support/core_ext/name_error'
+require 'active_support/core_ext/uri'
require 'active_support/inflector'
@@ -141,8 +141,6 @@ def filter(controller)
end
class ActionCachePath
- include UriParser
-
attr_reader :path, :extension
# If +infer_extension+ is true, the cache path extension is looked up from the request's
@@ -163,7 +161,7 @@ def initialize(controller, options = {}, infer_extension = true)
def normalize!(path)
path << 'index' if path[-1] == ?/
path << ".#{extension}" if extension and !path.ends_with?(extension)
- uri_parser.unescape(path)
+ URI.parser.unescape(path)
end
end
end
@@ -57,8 +57,6 @@ module Pages
end
module ClassMethods
- include UriParser
-
# Expires the page that was cached with the +path+ as a key. Example:
# expire_page "/lists/show"
def expire_page(path)
@@ -100,7 +98,7 @@ def caches_page(*actions)
private
def page_cache_file(path)
- name = (path.empty? || path == "/") ? "/index" : uri_parser.unescape(path.chomp('/'))
+ name = (path.empty? || path == "/") ? "/index" : URI.parser.unescape(path.chomp('/'))
name << page_cache_extension unless (name.split('/').last || name).include? '.'
return name
end
@@ -112,10 +110,6 @@ def page_cache_path(path)
def instrument_page_cache(name, path)
ActiveSupport::Notifications.instrument("#{name}.action_controller", :path => path){ yield }
end
-
- def uri_parser
- @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI
- end
end
# Expires the page that was cached with the +options+ as a key. Example:
@@ -1,9 +0,0 @@
-require 'uri'
-
-module ActionController #:nodoc:
- module UriParser
- def uri_parser
- @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI
- end
- end
-end
@@ -5,8 +5,6 @@
module ActionDispatch
module Routing
class RouteSet #:nodoc:
- include ActionController::UriParser
-
PARAMETERS_KEY = 'action_dispatch.request.path_parameters'
class Dispatcher #:nodoc:
@@ -68,7 +66,7 @@ def merge_default_action!(params)
end
def split_glob_param!(params)
- params[@glob_param] = params[@glob_param].split('/').map { |v| uri_parser.unescape(v) }
+ params[@glob_param] = params[@glob_param].split('/').map { |v| URI.parser.unescape(v) }
end
end
@@ -546,7 +544,7 @@ def recognize_path(path, environment = {})
params.each do |key, value|
if value.is_a?(String)
value = value.dup.force_encoding(Encoding::BINARY) if value.encoding_aware?
- params[key] = uri_parser.unescape(value)
+ params[key] = URI.parser.unescape(value)
end
end
@@ -563,10 +561,6 @@ def recognize_path(path, environment = {})
end
private
- def uri_parser
- @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI
- end
-
def handle_positional_args(options)
return unless args = options.delete(:_positional_args)
@@ -12,6 +12,7 @@
require 'set'
require 'uri'
+require 'active_support/core_ext/uri'
require 'active_resource/exceptions'
require 'active_resource/connection'
require 'active_resource/formats'
@@ -414,8 +415,8 @@ def site=(site)
@site = nil
else
@site = create_site_uri_from(site)
- @user = uri_parser.unescape(@site.user) if @site.user
- @password = uri_parser.unescape(@site.password) if @site.password
+ @user = URI.parser.unescape(@site.user) if @site.user
+ @password = URI.parser.unescape(@site.password) if @site.password
end
end
@@ -588,7 +589,7 @@ def prefix_source
# Default value is <tt>site.path</tt>.
def prefix=(value = '/')
# Replace :placeholders with '#{embedded options[:lookups]}'
- prefix_call = value.gsub(/:\w+/) { |key| "\#{URI.escape options[#{key}].to_s}" }
+ prefix_call = value.gsub(/:\w+/) { |key| "\#{URI.parser.escape options[#{key}].to_s}" }
# Clear prefix parameters in case they have been cached
@prefix_parameters = nil
@@ -635,7 +636,7 @@ def element_path(id, prefix_options = {}, query_options = nil)
check_prefix_options(prefix_options)
prefix_options, query_options = split_options(prefix_options) if query_options.nil?
- "#{prefix(prefix_options)}#{collection_name}/#{URI.escape id.to_s}.#{format.extension}#{query_string(query_options)}"
+ "#{prefix(prefix_options)}#{collection_name}/#{URI.parser.escape id.to_s}.#{format.extension}#{query_string(query_options)}"
end
# Gets the new element path for REST resources.
@@ -916,12 +917,12 @@ def instantiate_record(record, prefix_options = {})
# Accepts a URI and creates the site URI from that.
def create_site_uri_from(site)
- site.is_a?(URI) ? site.dup : uri_parser.parse(site)
+ site.is_a?(URI) ? site.dup : URI.parser.parse(site)
end
# Accepts a URI and creates the proxy URI from that.
def create_proxy_uri_from(proxy)
- proxy.is_a?(URI) ? proxy.dup : uri_parser.parse(proxy)
+ proxy.is_a?(URI) ? proxy.dup : URI.parser.parse(proxy)
end
# contains a set of the current prefix parameters.
@@ -946,10 +947,6 @@ def split_options(options = {})
[ prefix_options, query_options ]
end
-
- def uri_parser
- @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI
- end
end
attr_accessor :attributes #:nodoc:
@@ -1,4 +1,5 @@
require 'active_support/core_ext/benchmark'
+require 'active_support/core_ext/uri'
require 'net/https'
require 'date'
require 'time'
@@ -31,21 +32,20 @@ def requests
def initialize(site, format = ActiveResource::Formats::XmlFormat)
raise ArgumentError, 'Missing site URI' unless site
@user = @password = nil
- @uri_parser = URI.const_defined?(:Parser) ? URI::Parser.new : URI
self.site = site
self.format = format
end
# Set URI for remote service.
def site=(site)
- @site = site.is_a?(URI) ? site : @uri_parser.parse(site)
- @user = @uri_parser.unescape(@site.user) if @site.user
- @password = @uri_parser.unescape(@site.password) if @site.password
+ @site = site.is_a?(URI) ? site : URI.parser.parse(site)
+ @user = URI.parser.unescape(@site.user) if @site.user
+ @password = URI.parser.unescape(@site.password) if @site.password
end
# Set the proxy for remote service.
def proxy=(proxy)
- @proxy = proxy.is_a?(URI) ? proxy : @uri_parser.parse(proxy)
+ @proxy = proxy.is_a?(URI) ? proxy : URI.parser.parse(proxy)
end
# Sets the user for remote service.
@@ -20,3 +20,11 @@ def unescape(str, escaped = /%[a-fA-F\d]{2}/)
end
end
end
+
+module URI
+ class << self
+ def parser
+ @parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI
+ end
+ end
+end

0 comments on commit 71acc27

Please sign in to comment.