aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2010-06-07 15:44:57 +0200
committerXavier Noria <fxn@hashref.com>2010-06-07 15:44:57 +0200
commit9e065c6bc175621ad30a416c8c4345f95ce3c264 (patch)
tree505df4243727a00d1f030205f2e64afe0d098e5e /activesupport/lib/active_support
parent0dbc732995a526354fb1e3c732af5dacdb863dda (diff)
parent1a8f784a236058101c6e8b6387aefc96e86a1e54 (diff)
downloadrails-9e065c6bc175621ad30a416c8c4345f95ce3c264.tar.gz
rails-9e065c6bc175621ad30a416c8c4345f95ce3c264.tar.bz2
rails-9e065c6bc175621ad30a416c8c4345f95ce3c264.zip
Merge remote branch 'rails/master'
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r--activesupport/lib/active_support/callbacks.rb9
-rw-r--r--activesupport/lib/active_support/core_ext/string/conversions.rb11
-rw-r--r--activesupport/lib/active_support/core_ext/string/inflections.rb11
-rw-r--r--activesupport/lib/active_support/core_ext/uri.rb8
-rw-r--r--activesupport/lib/active_support/dependencies.rb32
-rw-r--r--activesupport/lib/active_support/message_verifier.rb8
6 files changed, 59 insertions, 20 deletions
diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb
index 933667c909..ba15043bde 100644
--- a/activesupport/lib/active_support/callbacks.rb
+++ b/activesupport/lib/active_support/callbacks.rb
@@ -390,9 +390,12 @@ module ActiveSupport
undef_method "_run_#{symbol}_callbacks" if method_defined?("_run_#{symbol}_callbacks")
class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
def _run_#{symbol}_callbacks(key = nil, &blk)
- if self.class.send("_update_#{symbol}_superclass_callbacks")
- self.class.__define_runner(#{symbol.inspect})
- return _run_#{symbol}_callbacks(key, &blk)
+ @_initialized_#{symbol}_callbacks ||= begin
+ if self.class.send("_update_#{symbol}_superclass_callbacks")
+ self.class.__define_runner(#{symbol.inspect})
+ return _run_#{symbol}_callbacks(key, &blk)
+ end
+ true
end
if key
diff --git a/activesupport/lib/active_support/core_ext/string/conversions.rb b/activesupport/lib/active_support/core_ext/string/conversions.rb
index 6a243fe982..cd7a42ed2b 100644
--- a/activesupport/lib/active_support/core_ext/string/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/string/conversions.rb
@@ -47,4 +47,15 @@ class String
d[5] += d.pop
::DateTime.civil(*d)
end
+
+ # +constantize+ tries to find a declared constant with the name specified
+ # in the string. It raises a NameError when the name is not in CamelCase
+ # or is not initialized.
+ #
+ # Examples
+ # "Module".constantize # => Module
+ # "Class".constantize # => Class
+ def constantize
+ ActiveSupport::Inflector.constantize(self)
+ end
end
diff --git a/activesupport/lib/active_support/core_ext/string/inflections.rb b/activesupport/lib/active_support/core_ext/string/inflections.rb
index 48b028bb64..ef479d559e 100644
--- a/activesupport/lib/active_support/core_ext/string/inflections.rb
+++ b/activesupport/lib/active_support/core_ext/string/inflections.rb
@@ -146,15 +146,4 @@ class String
def foreign_key(separate_class_name_and_id_with_underscore = true)
ActiveSupport::Inflector.foreign_key(self, separate_class_name_and_id_with_underscore)
end
-
- # +constantize+ tries to find a declared constant with the name specified
- # in the string. It raises a NameError when the name is not in CamelCase
- # or is not initialized.
- #
- # Examples
- # "Module".constantize # => Module
- # "Class".constantize # => Class
- def constantize
- ActiveSupport::Inflector.constantize(self)
- end
end
diff --git a/activesupport/lib/active_support/core_ext/uri.rb b/activesupport/lib/active_support/core_ext/uri.rb
index 28eabd2111..b7fe0a6209 100644
--- a/activesupport/lib/active_support/core_ext/uri.rb
+++ b/activesupport/lib/active_support/core_ext/uri.rb
@@ -6,11 +6,15 @@ if RUBY_VERSION >= '1.9'
str = "\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E" # Ni-ho-nn-go in UTF-8, means Japanese.
parser = URI::Parser.new
+
unless str == parser.unescape(parser.escape(str))
URI::Parser.class_eval do
remove_method :unescape
- def unescape(str, escaped = @regexp[:ESCAPED])
- enc = (str.encoding == Encoding::US_ASCII) ? Encoding::UTF_8 : str.encoding
+ def unescape(str, escaped = /%[a-fA-F\d]{2}/)
+ # TODO: Are we actually sure that ASCII == UTF-8?
+ # YK: My initial experiments say yes, but let's be sure please
+ enc = str.encoding
+ enc = Encoding::UTF_8 if enc == Encoding::US_ASCII
str.gsub(escaped) { [$&[1, 2].hex].pack('C') }.force_encoding(enc)
end
end
diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb
index e14e225596..16c3bc1142 100644
--- a/activesupport/lib/active_support/dependencies.rb
+++ b/activesupport/lib/active_support/dependencies.rb
@@ -47,6 +47,9 @@ module ActiveSupport #:nodoc:
mattr_accessor :autoloaded_constants
self.autoloaded_constants = []
+ mattr_accessor :references
+ self.references = {}
+
# An array of constant names that need to be unloaded on every request. Used
# to allow arbitrary constants to be marked for unloading.
mattr_accessor :explicitly_unloadable_constants
@@ -476,9 +479,37 @@ module ActiveSupport #:nodoc:
def remove_unloadable_constants!
autoloaded_constants.each { |const| remove_constant const }
autoloaded_constants.clear
+ Reference.clear!
explicitly_unloadable_constants.each { |const| remove_constant const }
end
+ class Reference
+ @@constants = Hash.new { |h, k| h[k] = Inflector.constantize(k) }
+
+ attr_reader :name
+
+ def initialize(name)
+ @name = name.to_s
+ @@constants[@name] = name if name.respond_to?(:name)
+ end
+
+ def get
+ @@constants[@name]
+ end
+
+ def self.clear!
+ @@constants.clear
+ end
+ end
+
+ def ref(name)
+ references[name] ||= Reference.new(name)
+ end
+
+ def constantize(name)
+ ref(name).get
+ end
+
# Determine if the given constant has been automatically loaded.
def autoloaded?(desc)
# No name => anonymous module.
@@ -572,6 +603,7 @@ module ActiveSupport #:nodoc:
log "removing constant #{const}"
parent.instance_eval { remove_const to_remove }
+
return true
end
diff --git a/activesupport/lib/active_support/message_verifier.rb b/activesupport/lib/active_support/message_verifier.rb
index 6c46b68eaf..1031662293 100644
--- a/activesupport/lib/active_support/message_verifier.rb
+++ b/activesupport/lib/active_support/message_verifier.rb
@@ -47,11 +47,11 @@ module ActiveSupport
def secure_compare(a, b)
return false unless a.bytesize == b.bytesize
- l = a.unpack "C#{a.bytesize}"
+ l = a.unpack "C*"
- res = 0
- b.each_byte { |byte| res |= byte ^ l.shift }
- res == 0
+ res = true
+ b.each_byte { |byte| res = (byte == l.shift) && res }
+ res
end
def generate_digest(data)