From 6b135f7e465a6cd1c8162432f6e0caa820316c44 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Fri, 24 Sep 2010 15:42:52 -0300 Subject: Remove method if already exists to avoid warnings. --- activesupport/lib/active_support/core_ext/class/attribute.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/class/attribute.rb b/activesupport/lib/active_support/core_ext/class/attribute.rb index 688cba03db..8f0f50919f 100644 --- a/activesupport/lib/active_support/core_ext/class/attribute.rb +++ b/activesupport/lib/active_support/core_ext/class/attribute.rb @@ -75,6 +75,7 @@ class Class val end + remove_method :#{name} if method_defined?(:#{name}) def #{name} defined?(@#{name}) ? @#{name} : singleton_class.#{name} end -- cgit v1.2.3 From 918dc27345319fbabf25a43bd65b613878b3a66e Mon Sep 17 00:00:00 2001 From: thedarkone Date: Mon, 27 Sep 2010 14:50:39 +0200 Subject: Compile ActionController::Base.config's methods to avoid method_missing overhead. --- activesupport/lib/active_support/configurable.rb | 24 ++++++++++++++++++++-- .../lib/active_support/ordered_options.rb | 4 ++++ activesupport/test/configurable_test.rb | 18 ++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/configurable.rb b/activesupport/lib/active_support/configurable.rb index 5b85f9394a..36634bd7f3 100644 --- a/activesupport/lib/active_support/configurable.rb +++ b/activesupport/lib/active_support/configurable.rb @@ -9,9 +9,29 @@ module ActiveSupport module Configurable extend ActiveSupport::Concern + class Configuration < ActiveSupport::InheritableOptions + def crystalize! + self.class.crystalize!(keys.reject {|key| respond_to?(key)}) + end + + # compiles reader methods so we don't have to go through method_missing + def self.crystalize!(keys) + keys.each do |key| + class_eval <<-RUBY, __FILE__, __LINE__ + 1 + def #{key}; self[#{key.inspect}]; end + RUBY + end + end + end + module ClassMethods def config - @_config ||= ActiveSupport::InheritableOptions.new(superclass.respond_to?(:config) ? superclass.config : {}) + @_config ||= if superclass.respond_to?(:config) + superclass.config.inheritable_copy + else + # create a new "anonymous" class that will host the compiled reader methods + Class.new(Configuration).new({}) + end end def configure @@ -48,7 +68,7 @@ module ActiveSupport # user.config.level # => 1 # def config - @_config ||= ActiveSupport::InheritableOptions.new(self.class.config) + @_config ||= self.class.config.inheritable_copy end end end diff --git a/activesupport/lib/active_support/ordered_options.rb b/activesupport/lib/active_support/ordered_options.rb index 37e357552c..2b67e72cff 100644 --- a/activesupport/lib/active_support/ordered_options.rb +++ b/activesupport/lib/active_support/ordered_options.rb @@ -39,5 +39,9 @@ module ActiveSupport #:nodoc: def initialize(parent) super() { |h,k| parent[k] } end + + def inheritable_copy + self.class.new(self) + end end end diff --git a/activesupport/test/configurable_test.rb b/activesupport/test/configurable_test.rb index cef67e3cf9..4f288eb4d5 100644 --- a/activesupport/test/configurable_test.rb +++ b/activesupport/test/configurable_test.rb @@ -39,4 +39,22 @@ class ConfigurableActiveSupport < ActiveSupport::TestCase assert_equal :baz, instance.config.foo assert_equal :bar, Parent.config.foo end + + test "configuration is crystalizeable" do + parent = Class.new { include ActiveSupport::Configurable } + child = Class.new(parent) + + parent.config.bar = :foo + assert !parent.config.respond_to?(:bar) + assert !child.config.respond_to?(:bar) + assert !child.new.config.respond_to?(:bar) + + parent.config.crystalize! + assert_equal :foo, parent.config.bar + assert_equal :foo, child.new.config.bar + + assert_respond_to parent.config, :bar + assert_respond_to child.config, :bar + assert_respond_to child.new.config, :bar + end end \ No newline at end of file -- cgit v1.2.3 From 8cda132136a766621b4c976cb1df7007d12ee6b5 Mon Sep 17 00:00:00 2001 From: thedarkone Date: Mon, 27 Sep 2010 14:51:31 +0200 Subject: Make InheritableOptions's constructor more flexible. --- activesupport/lib/active_support/configurable.rb | 2 +- activesupport/lib/active_support/ordered_options.rb | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/configurable.rb b/activesupport/lib/active_support/configurable.rb index 36634bd7f3..3d91560833 100644 --- a/activesupport/lib/active_support/configurable.rb +++ b/activesupport/lib/active_support/configurable.rb @@ -30,7 +30,7 @@ module ActiveSupport superclass.config.inheritable_copy else # create a new "anonymous" class that will host the compiled reader methods - Class.new(Configuration).new({}) + Class.new(Configuration).new end end diff --git a/activesupport/lib/active_support/ordered_options.rb b/activesupport/lib/active_support/ordered_options.rb index 2b67e72cff..99c6c5a0c0 100644 --- a/activesupport/lib/active_support/ordered_options.rb +++ b/activesupport/lib/active_support/ordered_options.rb @@ -36,8 +36,12 @@ module ActiveSupport #:nodoc: end class InheritableOptions < OrderedOptions - def initialize(parent) - super() { |h,k| parent[k] } + def initialize(parent = nil) + if parent + super() { |h,k| parent[k] } + else + super() + end end def inheritable_copy -- cgit v1.2.3 From 5a518487fe66b11b81e21dc6c31d036057a410ed Mon Sep 17 00:00:00 2001 From: thedarkone Date: Mon, 27 Sep 2010 14:48:06 +0200 Subject: Try to use Hash's native #[] for speed. --- activesupport/lib/active_support/configurable.rb | 2 +- activesupport/lib/active_support/ordered_options.rb | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/configurable.rb b/activesupport/lib/active_support/configurable.rb index 3d91560833..1914f10669 100644 --- a/activesupport/lib/active_support/configurable.rb +++ b/activesupport/lib/active_support/configurable.rb @@ -18,7 +18,7 @@ module ActiveSupport def self.crystalize!(keys) keys.each do |key| class_eval <<-RUBY, __FILE__, __LINE__ + 1 - def #{key}; self[#{key.inspect}]; end + def #{key}; _get(#{key.inspect}); end RUBY end end diff --git a/activesupport/lib/active_support/ordered_options.rb b/activesupport/lib/active_support/ordered_options.rb index 99c6c5a0c0..124e1a74f8 100644 --- a/activesupport/lib/active_support/ordered_options.rb +++ b/activesupport/lib/active_support/ordered_options.rb @@ -18,6 +18,9 @@ require 'active_support/ordered_hash' # module ActiveSupport #:nodoc: class OrderedOptions < OrderedHash + alias_method :_get, :[] # preserve the original #[] method + protected :_get # make it protected + def []=(key, value) super(key.to_sym, value) end @@ -37,7 +40,10 @@ module ActiveSupport #:nodoc: class InheritableOptions < OrderedOptions def initialize(parent = nil) - if parent + if parent.kind_of?(OrderedOptions) + # use the faster _get when dealing with OrderedOptions + super() { |h,k| parent._get(k) } + elsif parent super() { |h,k| parent[k] } else super() -- cgit v1.2.3 From 320382ccd359397f2c83f8c0c622b296dcfb472b Mon Sep 17 00:00:00 2001 From: thedarkone Date: Fri, 24 Sep 2010 18:01:47 +0200 Subject: Creating singleton class for every object whenever the instance-level accessor is used quite is expensive. --- .../lib/active_support/core_ext/class/attribute.rb | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/class/attribute.rb b/activesupport/lib/active_support/core_ext/class/attribute.rb index 688cba03db..511f26963e 100644 --- a/activesupport/lib/active_support/core_ext/class/attribute.rb +++ b/activesupport/lib/active_support/core_ext/class/attribute.rb @@ -72,11 +72,20 @@ class Class remove_possible_method(:#{name}) define_method(:#{name}) { val } end + + if singleton_class? + class_eval do + remove_possible_method(:#{name}) + def #{name} + defined?(@#{name}) ? @#{name} : singleton_class.#{name} + end + end + end val end def #{name} - defined?(@#{name}) ? @#{name} : singleton_class.#{name} + defined?(@#{name}) ? @#{name} : self.class.#{name} end def #{name}? @@ -87,4 +96,15 @@ class Class attr_writer name if instance_writer end end + + private + def singleton_class? + # in case somebody is crazy enough to overwrite allocate + allocate = Class.instance_method(:allocate) + # object.class always points to a real (non-singleton) class + allocate.bind(self).call.class != self + rescue TypeError + # MRI/YARV/JRuby all disallow creating new instances of a singleton class + true + end end -- cgit v1.2.3 From f2e0b3575e8c84cd23b75fcbfee83e7c683781ef Mon Sep 17 00:00:00 2001 From: thedarkone Date: Sun, 26 Sep 2010 17:05:54 +0200 Subject: Use native attr_* macros for performance reasons. --- .../active_support/core_ext/module/attr_internal.rb | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/module/attr_internal.rb b/activesupport/lib/active_support/core_ext/module/attr_internal.rb index 28bc30ae26..00db75bfec 100644 --- a/activesupport/lib/active_support/core_ext/module/attr_internal.rb +++ b/activesupport/lib/active_support/core_ext/module/attr_internal.rb @@ -1,16 +1,12 @@ class Module # Declares an attribute reader backed by an internally-named instance variable. def attr_internal_reader(*attrs) - attrs.each do |attr| - module_eval "def #{attr}() #{attr_internal_ivar_name(attr)} end", __FILE__, __LINE__ - end + attrs.each {|attr_name| attr_internal_define(attr_name, :reader)} end # Declares an attribute writer backed by an internally-named instance variable. def attr_internal_writer(*attrs) - attrs.each do |attr| - module_eval "def #{attr}=(v) #{attr_internal_ivar_name(attr)} = v end", __FILE__, __LINE__ - end + attrs.each {|attr_name| attr_internal_define(attr_name, :writer)} end # Declares an attribute reader and writer backed by an internally-named instance @@ -29,4 +25,15 @@ class Module def attr_internal_ivar_name(attr) Module.attr_internal_naming_format % attr end + + def attr_internal_define(attr_name, type) + internal_name = attr_internal_ivar_name(attr_name).sub(/\A@/, '') + class_eval do # class_eval is necessary on 1.9 or else the methods a made private + # use native attr_* methods as they are faster on some Ruby implementations + send("attr_#{type}", internal_name) + end + attr_name, internal_name = "#{attr_name}=", "#{internal_name}=" if type == :writer + alias_method attr_name, internal_name + remove_method internal_name + end end -- cgit v1.2.3 From 4c360c15e53324a7e5940f943129a06da51ac7d3 Mon Sep 17 00:00:00 2001 From: thedarkone Date: Fri, 24 Sep 2010 23:09:12 +0200 Subject: No need for an extra wrapper array. --- activesupport/lib/active_support/core_ext/hash/keys.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/hash/keys.rb b/activesupport/lib/active_support/core_ext/hash/keys.rb index 045a6944fa..2cb2c89d30 100644 --- a/activesupport/lib/active_support/core_ext/hash/keys.rb +++ b/activesupport/lib/active_support/core_ext/hash/keys.rb @@ -39,7 +39,7 @@ class Hash # { :name => "Rob", :age => "28" }.assert_valid_keys("name", "age") # => raises "ArgumentError: Unknown key(s): name, age" # { :name => "Rob", :age => "28" }.assert_valid_keys(:name, :age) # => passes, raises nothing def assert_valid_keys(*valid_keys) - unknown_keys = keys - [valid_keys].flatten + unknown_keys = keys - valid_keys.flatten raise(ArgumentError, "Unknown key(s): #{unknown_keys.join(", ")}") unless unknown_keys.empty? end end -- cgit v1.2.3 From 77efc20a54708ba37ba679ffe90021bf8a8d3a8a Mon Sep 17 00:00:00 2001 From: thedarkone Date: Fri, 24 Sep 2010 23:21:59 +0200 Subject: Make assert_valid_keys slightly faster. --- activesupport/lib/active_support/core_ext/hash/keys.rb | 10 ++++++---- activesupport/test/core_ext/hash_ext_test.rb | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/hash/keys.rb b/activesupport/lib/active_support/core_ext/hash/keys.rb index 2cb2c89d30..d8748b1138 100644 --- a/activesupport/lib/active_support/core_ext/hash/keys.rb +++ b/activesupport/lib/active_support/core_ext/hash/keys.rb @@ -35,11 +35,13 @@ class Hash # as keys, this will fail. # # ==== Examples - # { :name => "Rob", :years => "28" }.assert_valid_keys(:name, :age) # => raises "ArgumentError: Unknown key(s): years" - # { :name => "Rob", :age => "28" }.assert_valid_keys("name", "age") # => raises "ArgumentError: Unknown key(s): name, age" + # { :name => "Rob", :years => "28" }.assert_valid_keys(:name, :age) # => raises "ArgumentError: Unknown key: years" + # { :name => "Rob", :age => "28" }.assert_valid_keys("name", "age") # => raises "ArgumentError: Unknown key: name" # { :name => "Rob", :age => "28" }.assert_valid_keys(:name, :age) # => passes, raises nothing def assert_valid_keys(*valid_keys) - unknown_keys = keys - valid_keys.flatten - raise(ArgumentError, "Unknown key(s): #{unknown_keys.join(", ")}") unless unknown_keys.empty? + valid_keys.flatten! + each_key do |k| + raise(ArgumentError, "Unknown key: #{k}") unless valid_keys.include?(k) + end end end diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index fc8d8170a1..e5438745e0 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -282,7 +282,7 @@ class HashExtTest < Test::Unit::TestCase { :failure => "stuff", :funny => "business" }.assert_valid_keys(:failure, :funny) end - assert_raise(ArgumentError, "Unknown key(s): failore") do + assert_raise(ArgumentError, "Unknown key: failore") do { :failore => "stuff", :funny => "business" }.assert_valid_keys([ :failure, :funny ]) { :failore => "stuff", :funny => "business" }.assert_valid_keys(:failure, :funny) end -- cgit v1.2.3 From 6067d1620075c1c311bbae01993453cd80967804 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 27 Sep 2010 20:42:02 +0200 Subject: Call it compile_methods! and do the same on AM. --- activesupport/lib/active_support/configurable.rb | 6 +++--- activesupport/test/configurable_test.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/configurable.rb b/activesupport/lib/active_support/configurable.rb index 1914f10669..58ed37b018 100644 --- a/activesupport/lib/active_support/configurable.rb +++ b/activesupport/lib/active_support/configurable.rb @@ -10,12 +10,12 @@ module ActiveSupport extend ActiveSupport::Concern class Configuration < ActiveSupport::InheritableOptions - def crystalize! - self.class.crystalize!(keys.reject {|key| respond_to?(key)}) + def compile_methods! + self.class.compile_methods!(keys.reject {|key| respond_to?(key)}) end # compiles reader methods so we don't have to go through method_missing - def self.crystalize!(keys) + def self.compile_methods!(keys) keys.each do |key| class_eval <<-RUBY, __FILE__, __LINE__ + 1 def #{key}; _get(#{key.inspect}); end diff --git a/activesupport/test/configurable_test.rb b/activesupport/test/configurable_test.rb index 4f288eb4d5..9c773c1944 100644 --- a/activesupport/test/configurable_test.rb +++ b/activesupport/test/configurable_test.rb @@ -49,7 +49,7 @@ class ConfigurableActiveSupport < ActiveSupport::TestCase assert !child.config.respond_to?(:bar) assert !child.new.config.respond_to?(:bar) - parent.config.crystalize! + parent.config.compile_methods! assert_equal :foo, parent.config.bar assert_equal :foo, child.new.config.bar -- cgit v1.2.3 From 72c1e19c33ca06008d5d64619a533bdf34e3fc2b Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Sat, 25 Sep 2010 18:30:56 -0400 Subject: after_create in ActiveModel should in the order specified MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [#5650 state:resolved] Signed-off-by: José Valim --- activesupport/lib/active_support/callbacks.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index d811c3b2f0..0c1d46c7ec 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -482,7 +482,7 @@ module ActiveSupport chain.delete_if {|c| c.matches?(type, filter) } end - options[:prepend] ? chain.unshift(*mapped) : chain.push(*mapped) + options[:prepend] ? chain.unshift(*(mapped.reverse)) : chain.push(*mapped) end end -- cgit v1.2.3 From bfc986811c5cbcfcc856916a1b09fcbf6551ecf5 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Sat, 25 Sep 2010 18:31:43 -0400 Subject: Test for after_create callback order in ActiveSupport [#5703 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- activesupport/test/callbacks_test.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'activesupport') diff --git a/activesupport/test/callbacks_test.rb b/activesupport/test/callbacks_test.rb index 292383e3d8..51b28b6a43 100644 --- a/activesupport/test/callbacks_test.rb +++ b/activesupport/test/callbacks_test.rb @@ -149,6 +149,27 @@ module CallbacksTest end end + class AfterSaveConditionalPerson < Record + after_save Proc.new { |r| r.history << [:after_save, :string1] } + after_save Proc.new { |r| r.history << [:after_save, :string2] } + def save + run_callbacks :save + end + end + + class AfterSaveConditionalPersonCallbackTest < Test::Unit::TestCase + def test_after_save_runs_in_the_reverse_order + person = AfterSaveConditionalPerson.new + person.save + assert_equal [ + [:after_save, :string2], + [:after_save, :string1] + ], person.history + end + end + + + class ConditionalPerson < Record # proc before_save Proc.new { |r| r.history << [:before_save, :proc] }, :if => Proc.new { |r| true } @@ -352,6 +373,8 @@ module CallbacksTest end end + + class ResetCallbackTest < Test::Unit::TestCase def test_save_conditional_person person = CleanPerson.new -- cgit v1.2.3 From 10dec0e65e1f4d87f411b4361045eba86b121be9 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 28 Sep 2010 00:32:20 +0200 Subject: let Hash#to_param and Hash#to_query sort again This was a regression introduced in 5c858220085dc4ddc1bec496747059dfbe32f1da. We bring sorting back because people rely on it, eg for constructing consistent cache keys. --- activesupport/lib/active_support/core_ext/object/to_param.rb | 5 +++-- activesupport/test/core_ext/hash_ext_test.rb | 10 +++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/object/to_param.rb b/activesupport/lib/active_support/core_ext/object/to_param.rb index f2e7c2351e..3a18e2a121 100644 --- a/activesupport/lib/active_support/core_ext/object/to_param.rb +++ b/activesupport/lib/active_support/core_ext/object/to_param.rb @@ -35,7 +35,8 @@ end class Hash # Converts a hash into a string suitable for use as a URL query string. An optional namespace can be - # passed to enclose the param names (see example below). + # passed to enclose the param names (see example below). The keys in the query string are sorted lexicographically + # in ascending order. # # ==== Examples # { :name => 'David', :nationality => 'Danish' }.to_param # => "name=David&nationality=Danish" @@ -44,6 +45,6 @@ class Hash def to_param(namespace = nil) collect do |key, value| value.to_query(namespace ? "#{namespace}[#{key}]" : key) - end * '&' + end.sort * '&' end end diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index e5438745e0..0f35eb9e78 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -462,20 +462,24 @@ class HashExtToParamTests < Test::Unit::TestCase assert_equal '', {}.to_param assert_equal 'hello=world', { :hello => "world" }.to_param assert_equal 'hello=10', { "hello" => 10 }.to_param - assert_equal 'hello=world&say_bye=true', ActiveSupport::OrderedHash[:hello, "world", "say_bye", true].to_param + assert_equal 'hello=world&say_bye=true', {:hello => "world", "say_bye" => true}.to_param end def test_number_hash - assert_equal '10=20&30=40&50=60', ActiveSupport::OrderedHash[10, 20, 30, 40, 50, 60].to_param + assert_equal '10=20&30=40&50=60', {10 => 20, 30 => 40, 50 => 60}.to_param end def test_to_param_hash - assert_equal 'custom=param-1&custom2=param2-1', ActiveSupport::OrderedHash[ToParam.new('custom'), ToParam.new('param'), ToParam.new('custom2'), ToParam.new('param2')].to_param + assert_equal 'custom2=param2-1&custom=param-1', {ToParam.new('custom') => ToParam.new('param'), ToParam.new('custom2') => ToParam.new('param2')}.to_param end def test_to_param_hash_escapes_its_keys_and_values assert_equal 'param+1=A+string+with+%2F+characters+%26+that+should+be+%3F+escaped', { 'param 1' => 'A string with / characters & that should be ? escaped' }.to_param end + + def test_to_param_orders_by_key_in_ascending_order + assert_equal 'a=2&b=1&c=0', ActiveSupport::OrderedHash[*%w(b 1 c 0 a 2)].to_param + end end class HashToXmlTest < Test::Unit::TestCase -- cgit v1.2.3 From dc5336e7f4f7128fc102ab17b63bed46d1b0db3e Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 28 Sep 2010 00:36:53 +0200 Subject: revises RDoc of Hash#to_param to be more precise about ordering --- activesupport/lib/active_support/core_ext/object/to_param.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/object/to_param.rb b/activesupport/lib/active_support/core_ext/object/to_param.rb index 3a18e2a121..ecb2bca82c 100644 --- a/activesupport/lib/active_support/core_ext/object/to_param.rb +++ b/activesupport/lib/active_support/core_ext/object/to_param.rb @@ -35,8 +35,8 @@ end class Hash # Converts a hash into a string suitable for use as a URL query string. An optional namespace can be - # passed to enclose the param names (see example below). The keys in the query string are sorted lexicographically - # in ascending order. + # passed to enclose the param names (see example below). The string pairs "key=value" that conform the query + # string are sorted lexicographically in ascending order. # # ==== Examples # { :name => 'David', :nationality => 'Danish' }.to_param # => "name=David&nationality=Danish" -- cgit v1.2.3 From 71acc2737aa346ee57f9fc21252a508ae83367a4 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 07:57:26 +0800 Subject: Move uri parser to AS as URI.parser method to reuse it in AP and ARes. --- activesupport/lib/active_support/core_ext/uri.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/uri.rb b/activesupport/lib/active_support/core_ext/uri.rb index b7fe0a6209..ee991e3439 100644 --- a/activesupport/lib/active_support/core_ext/uri.rb +++ b/activesupport/lib/active_support/core_ext/uri.rb @@ -20,3 +20,11 @@ if RUBY_VERSION >= '1.9' end end end + +module URI + class << self + def parser + @parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI + end + end +end -- cgit v1.2.3