aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2010-03-12 16:00:01 +0000
committerPratik Naik <pratiknaik@gmail.com>2010-03-12 16:00:01 +0000
commite68bfaf1fe1a7890a67af6f444281185f507cf9e (patch)
tree5e73caccdcdd65d0ac97f9eb92195928f30925f2 /activesupport/lib/active_support
parentef6462c73003b28c8e060a06120abb9cd67b6d52 (diff)
parent16846553b8866eab2aa3b128a2a23a221a25f7e3 (diff)
downloadrails-e68bfaf1fe1a7890a67af6f444281185f507cf9e.tar.gz
rails-e68bfaf1fe1a7890a67af6f444281185f507cf9e.tar.bz2
rails-e68bfaf1fe1a7890a67af6f444281185f507cf9e.zip
Merge remote branch 'mainstream/master'
Conflicts: activerecord/lib/active_record/base.rb railties/lib/rails/configuration.rb railties/lib/rails/log_subscriber.rb
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r--activesupport/lib/active_support/all.rb1
-rw-r--r--activesupport/lib/active_support/callbacks.rb4
-rw-r--r--activesupport/lib/active_support/core_ext/array/conversions.rb1
-rw-r--r--activesupport/lib/active_support/core_ext/class/attribute.rb32
-rw-r--r--activesupport/lib/active_support/core_ext/class/delegating_attributes.rb12
-rw-r--r--activesupport/lib/active_support/core_ext/file/atomic.rb3
-rw-r--r--activesupport/lib/active_support/core_ext/file/path.rb5
-rw-r--r--activesupport/lib/active_support/core_ext/hash/keys.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/object.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/object/metaclass.rb13
-rw-r--r--activesupport/lib/active_support/core_ext/object/singleton_class.rb13
-rw-r--r--activesupport/lib/active_support/core_ext/proc.rb6
-rw-r--r--activesupport/lib/active_support/core_ext/string/conversions.rb1
-rw-r--r--activesupport/lib/active_support/core_ext/string/inflections.rb4
-rw-r--r--activesupport/lib/active_support/core_ext/string/interpolation.rb92
-rw-r--r--activesupport/lib/active_support/core_ext/string/output_safety.rb8
-rw-r--r--activesupport/lib/active_support/dependencies.rb23
-rw-r--r--activesupport/lib/active_support/dependencies/autoload.rb5
-rw-r--r--activesupport/lib/active_support/deprecation/method_wrappers.rb18
-rw-r--r--activesupport/lib/active_support/deprecation/reporting.rb3
-rw-r--r--activesupport/lib/active_support/i18n.rb3
-rw-r--r--activesupport/lib/active_support/inflector/methods.rb2
-rw-r--r--activesupport/lib/active_support/inflector/transliterate.rb2
-rw-r--r--activesupport/lib/active_support/json/decoding.rb2
-rw-r--r--activesupport/lib/active_support/lazy_load_hooks.rb25
-rw-r--r--activesupport/lib/active_support/memoizable.rb2
-rw-r--r--activesupport/lib/active_support/notifications.rb10
-rw-r--r--activesupport/lib/active_support/notifications/fanout.rb22
-rw-r--r--activesupport/lib/active_support/ordered_options.rb6
-rw-r--r--activesupport/lib/active_support/railtie.rb12
-rw-r--r--activesupport/lib/active_support/ruby/shim.rb1
-rw-r--r--activesupport/lib/active_support/version.rb5
-rw-r--r--activesupport/lib/active_support/whiny_nil.rb7
33 files changed, 181 insertions, 166 deletions
diff --git a/activesupport/lib/active_support/all.rb b/activesupport/lib/active_support/all.rb
index 64600575d9..f537818300 100644
--- a/activesupport/lib/active_support/all.rb
+++ b/activesupport/lib/active_support/all.rb
@@ -1,4 +1,3 @@
require 'active_support'
-require 'active_support/i18n'
require 'active_support/time'
require 'active_support/core_ext'
diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb
index 6727eda811..b230bb8a40 100644
--- a/activesupport/lib/active_support/callbacks.rb
+++ b/activesupport/lib/active_support/callbacks.rb
@@ -1,7 +1,7 @@
require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/class/inheritable_attributes'
require 'active_support/core_ext/kernel/reporting'
-require 'active_support/core_ext/object/metaclass'
+require 'active_support/core_ext/object/singleton_class'
module ActiveSupport
# Callbacks are hooks into the lifecycle of an object that allow you to trigger logic
@@ -312,7 +312,7 @@ module ActiveSupport
def _normalize_legacy_filter(kind, filter)
if !filter.respond_to?(kind) && filter.respond_to?(:filter)
- filter.metaclass.class_eval(
+ filter.singleton_class.class_eval(
"def #{kind}(context, &block) filter(context, &block) end",
__FILE__, __LINE__ - 1)
elsif filter.respond_to?(:before) && filter.respond_to?(:after) && kind == :around
diff --git a/activesupport/lib/active_support/core_ext/array/conversions.rb b/activesupport/lib/active_support/core_ext/array/conversions.rb
index 814567a5a6..2119322bfe 100644
--- a/activesupport/lib/active_support/core_ext/array/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/array/conversions.rb
@@ -1,7 +1,6 @@
require 'active_support/core_ext/hash/keys'
require 'active_support/core_ext/hash/reverse_merge'
require 'active_support/inflector'
-require 'active_support/i18n'
class Array
# Converts the array to a comma-separated sentence where the last element is joined by the connector word. Options:
diff --git a/activesupport/lib/active_support/core_ext/class/attribute.rb b/activesupport/lib/active_support/core_ext/class/attribute.rb
index d74219cb93..c18905b369 100644
--- a/activesupport/lib/active_support/core_ext/class/attribute.rb
+++ b/activesupport/lib/active_support/core_ext/class/attribute.rb
@@ -1,4 +1,4 @@
-require 'active_support/core_ext/object/metaclass'
+require 'active_support/core_ext/object/singleton_class'
require 'active_support/core_ext/module/delegation'
class Class
@@ -24,13 +24,35 @@ class Class
# For convenience, a query method is defined as well:
#
# Subclass.setting? # => false
+ #
+ # Instances may overwrite the class value in the same way:
+ #
+ # Base.setting = true
+ # object = Base.new
+ # object.setting # => true
+ # object.setting = false
+ # object.setting # => false
+ # Base.setting # => true
+ #
+ # To opt out of the instance writer method, pass :instance_writer => false.
+ #
+ # object.setting = false # => NoMethodError
def class_attribute(*attrs)
+ instance_writer = !attrs.last.is_a?(Hash) || attrs.pop[:instance_writer]
+
+ s = singleton_class
attrs.each do |attr|
- metaclass.send(:define_method, attr) { }
- metaclass.send(:define_method, "#{attr}?") { !!send(attr) }
- metaclass.send(:define_method, "#{attr}=") do |value|
- metaclass.send(:define_method, attr) { value }
+ s.send(:define_method, attr) { }
+ s.send(:define_method, :"#{attr}?") { !!send(attr) }
+ s.send(:define_method, :"#{attr}=") do |value|
+ singleton_class.send(:define_method, attr) { value }
end
+
+ define_method(attr) { self.class.send(attr) }
+ define_method(:"#{attr}?") { !!send(attr) }
+ define_method(:"#{attr}=") do |value|
+ singleton_class.send(:define_method, attr) { value }
+ end if instance_writer
end
end
end
diff --git a/activesupport/lib/active_support/core_ext/class/delegating_attributes.rb b/activesupport/lib/active_support/core_ext/class/delegating_attributes.rb
index 19382abb76..b5785bdcd3 100644
--- a/activesupport/lib/active_support/core_ext/class/delegating_attributes.rb
+++ b/activesupport/lib/active_support/core_ext/class/delegating_attributes.rb
@@ -1,6 +1,6 @@
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/array/extract_options'
-require 'active_support/core_ext/object/metaclass'
+require 'active_support/core_ext/object/singleton_class'
class Class
def superclass_delegating_accessor(name, options = {})
@@ -11,9 +11,9 @@ class Class
# Generate the public methods name, name=, and name?
# These methods dispatch to the private _name, and _name= methods, making them
# overridable
- metaclass.send(:define_method, name) { send("_#{name}") }
- metaclass.send(:define_method, "#{name}?") { !!send("_#{name}") }
- metaclass.send(:define_method, "#{name}=") { |value| send("_#{name}=", value) }
+ singleton_class.send(:define_method, name) { send("_#{name}") }
+ singleton_class.send(:define_method, "#{name}?") { !!send("_#{name}") }
+ singleton_class.send(:define_method, "#{name}=") { |value| send("_#{name}=", value) }
# If an instance_reader is needed, generate methods for name and name= on the
# class itself, so instances will be able to see them
@@ -27,12 +27,12 @@ private
# inheritance behavior, without having to store the object in an instance
# variable and look up the superclass chain manually.
def _stash_object_in_method(object, method, instance_reader = true)
- metaclass.send(:define_method, method) { object }
+ singleton_class.send(:define_method, method) { object }
define_method(method) { object } if instance_reader
end
def _superclass_delegating_accessor(name, options = {})
- metaclass.send(:define_method, "#{name}=") do |value|
+ singleton_class.send(:define_method, "#{name}=") do |value|
_stash_object_in_method(value, name, options[:instance_reader] != false)
end
self.send("#{name}=", nil)
diff --git a/activesupport/lib/active_support/core_ext/file/atomic.rb b/activesupport/lib/active_support/core_ext/file/atomic.rb
index 49d28e8a34..26b73ed442 100644
--- a/activesupport/lib/active_support/core_ext/file/atomic.rb
+++ b/activesupport/lib/active_support/core_ext/file/atomic.rb
@@ -14,6 +14,7 @@ class File
# end
def self.atomic_write(file_name, temp_dir = Dir.tmpdir)
require 'tempfile' unless defined?(Tempfile)
+ require 'fileutils' unless defined?(FileUtils)
temp_file = Tempfile.new(basename(file_name), temp_dir)
yield temp_file
@@ -31,7 +32,7 @@ class File
end
# Overwrite original file with temp file
- rename(temp_file.path, file_name)
+ FileUtils.mv(temp_file.path, file_name)
# Set correct permissions on new file
chown(old_stat.uid, old_stat.gid, file_name)
diff --git a/activesupport/lib/active_support/core_ext/file/path.rb b/activesupport/lib/active_support/core_ext/file/path.rb
new file mode 100644
index 0000000000..b5feab80ae
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/file/path.rb
@@ -0,0 +1,5 @@
+class File
+ unless File.allocate.respond_to?(:to_path)
+ alias to_path path
+ end
+end \ No newline at end of file
diff --git a/activesupport/lib/active_support/core_ext/hash/keys.rb b/activesupport/lib/active_support/core_ext/hash/keys.rb
index 045a6944fa..e4d429fc2b 100644
--- a/activesupport/lib/active_support/core_ext/hash/keys.rb
+++ b/activesupport/lib/active_support/core_ext/hash/keys.rb
@@ -22,7 +22,7 @@ class Hash
# to +to_sym+.
def symbolize_keys!
keys.each do |key|
- self[(key.to_sym rescue key) || key] = delete(key)
+ self[(key.to_sym rescue key)] = delete(key) if key.respond_to?(:to_sym) && !key.is_a?(Fixnum)
end
self
end
diff --git a/activesupport/lib/active_support/core_ext/object.rb b/activesupport/lib/active_support/core_ext/object.rb
index db2dac1472..4f86d9d605 100644
--- a/activesupport/lib/active_support/core_ext/object.rb
+++ b/activesupport/lib/active_support/core_ext/object.rb
@@ -5,7 +5,7 @@ require 'active_support/core_ext/object/try'
require 'active_support/core_ext/object/conversions'
require 'active_support/core_ext/object/instance_variables'
-require 'active_support/core_ext/object/metaclass'
+require 'active_support/core_ext/object/singleton_class'
require 'active_support/core_ext/object/misc'
require 'active_support/core_ext/object/extending'
diff --git a/activesupport/lib/active_support/core_ext/object/metaclass.rb b/activesupport/lib/active_support/core_ext/object/metaclass.rb
deleted file mode 100644
index 93fb0ad594..0000000000
--- a/activesupport/lib/active_support/core_ext/object/metaclass.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-class Object
- # Get object's meta (ghost, eigenclass, singleton) class
- def metaclass
- class << self
- self
- end
- end
-
- # If class_eval is called on an object, add those methods to its metaclass
- def class_eval(*args, &block)
- metaclass.class_eval(*args, &block)
- end
-end
diff --git a/activesupport/lib/active_support/core_ext/object/singleton_class.rb b/activesupport/lib/active_support/core_ext/object/singleton_class.rb
new file mode 100644
index 0000000000..8dee54e71b
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/object/singleton_class.rb
@@ -0,0 +1,13 @@
+class Object
+ # Returns the object's singleton class.
+ def singleton_class
+ class << self
+ self
+ end
+ end unless respond_to?(:singleton_class)
+
+ # class_eval on an object acts like singleton_class_eval.
+ def class_eval(*args, &block)
+ singleton_class.class_eval(*args, &block)
+ end
+end
diff --git a/activesupport/lib/active_support/core_ext/proc.rb b/activesupport/lib/active_support/core_ext/proc.rb
index d50076a01e..71b413a88a 100644
--- a/activesupport/lib/active_support/core_ext/proc.rb
+++ b/activesupport/lib/active_support/core_ext/proc.rb
@@ -5,9 +5,9 @@ class Proc #:nodoc:
block, time = self, Time.now
object.class_eval do
method_name = "__bind_#{time.to_i}_#{time.usec}"
- define_method(method_name, &block) # define_method("__bind_1230458026_720454", &block)
- method = instance_method(method_name) # method = instance_method("__bind_1230458026_720454")
- remove_method(method_name) # remove_method("__bind_1230458026_720454")
+ define_method(method_name, &block)
+ method = instance_method(method_name)
+ remove_method(method_name)
method
end.bind(object)
end
diff --git a/activesupport/lib/active_support/core_ext/string/conversions.rb b/activesupport/lib/active_support/core_ext/string/conversions.rb
index 331416b3a9..52946f9037 100644
--- a/activesupport/lib/active_support/core_ext/string/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/string/conversions.rb
@@ -1,4 +1,5 @@
require 'date'
+require 'active_support/core_ext/time/publicize_conversion_methods'
require 'active_support/core_ext/time/calculations'
class String
diff --git a/activesupport/lib/active_support/core_ext/string/inflections.rb b/activesupport/lib/active_support/core_ext/string/inflections.rb
index ea4ed61e42..fbb7b79fc6 100644
--- a/activesupport/lib/active_support/core_ext/string/inflections.rb
+++ b/activesupport/lib/active_support/core_ext/string/inflections.rb
@@ -1,8 +1,10 @@
+require 'active_support/inflector'
+
# String inflections define new methods on the String class to transform names for different purposes.
# For instance, you can figure out the name of a database from the name of a class.
#
# "ScaleScore".tableize # => "scale_scores"
-
+#
class String
# Returns the plural form of the word in the string.
#
diff --git a/activesupport/lib/active_support/core_ext/string/interpolation.rb b/activesupport/lib/active_support/core_ext/string/interpolation.rb
index 06d3505c60..932117cc10 100644
--- a/activesupport/lib/active_support/core_ext/string/interpolation.rb
+++ b/activesupport/lib/active_support/core_ext/string/interpolation.rb
@@ -1,91 +1 @@
-=begin
- heavily based on Masao Mutoh's gettext String interpolation extension
- http://github.com/mutoh/gettext/blob/f6566738b981fe0952548c421042ad1e0cdfb31e/lib/gettext/core_ext/string.rb
- Copyright (C) 2005-2010 Masao Mutoh
- You may redistribute it and/or modify it under the same license terms as Ruby.
-=end
-
-if RUBY_VERSION < '1.9' && !"".respond_to?(:interpolate_without_ruby_19_syntax)
-
- # KeyError is raised by String#% when the string contains a named placeholder
- # that is not contained in the given arguments hash. Ruby 1.9 includes and
- # raises this exception natively. We define it to mimic Ruby 1.9's behaviour
- # in Ruby 1.8.x
-
- class KeyError < IndexError
- def initialize(message = nil)
- super(message || "key not found")
- end
- end unless defined?(KeyError)
-
- # Extension for String class. This feature is included in Ruby 1.9 or later but not occur TypeError.
- #
- # String#% method which accept "named argument". The translator can know
- # the meaning of the msgids using "named argument" instead of %s/%d style.
-
- class String
- alias :interpolate_without_ruby_19_syntax :% # :nodoc:
-
- INTERPOLATION_PATTERN = Regexp.union(
- /%%/,
- /%\{(\w+)\}/, # matches placeholders like "%{foo}"
- /%<(\w+)>(.*?\d*\.?\d*[bBdiouxXeEfgGcps])/ # matches placeholders like "%<foo>.d"
- )
-
- # % uses self (i.e. the String) as a format specification and returns the
- # result of applying it to the given arguments. In other words it interpolates
- # the given arguments to the string according to the formats the string
- # defines.
- #
- # There are three ways to use it:
- #
- # * Using a single argument or Array of arguments.
- #
- # This is the default behaviour of the String class. See Kernel#sprintf for
- # more details about the format string.
- #
- # Example:
- #
- # "%d %s" % [1, "message"]
- # # => "1 message"
- #
- # * Using a Hash as an argument and unformatted, named placeholders.
- #
- # When you pass a Hash as an argument and specify placeholders with %{foo}
- # it will interpret the hash values as named arguments.
- #
- # Example:
- #
- # "%{firstname}, %{lastname}" % {:firstname => "Masao", :lastname => "Mutoh"}
- # # => "Masao Mutoh"
- #
- # * Using a Hash as an argument and formatted, named placeholders.
- #
- # When you pass a Hash as an argument and specify placeholders with %<foo>d
- # it will interpret the hash values as named arguments and format the value
- # according to the formatting instruction appended to the closing >.
- #
- # Example:
- #
- # "%<integer>d, %<float>.1f" % { :integer => 10, :float => 43.4 }
- # # => "10, 43.3"
- def %(args)
- if args.kind_of?(Hash)
- dup.gsub(INTERPOLATION_PATTERN) do |match|
- if match == '%%'
- '%'
- else
- key = ($1 || $2).to_sym
- raise KeyError unless args.has_key?(key)
- $3 ? sprintf("%#{$3}", args[key]) : args[key]
- end
- end
- elsif self =~ INTERPOLATION_PATTERN
- raise ArgumentError.new('one hash required')
- else
- result = gsub(/%([{<])/, '%%\1')
- result.send :'interpolate_without_ruby_19_syntax', args
- end
- end
- end
-end
+require 'i18n/core_ext/string/interpolate'
diff --git a/activesupport/lib/active_support/core_ext/string/output_safety.rb b/activesupport/lib/active_support/core_ext/string/output_safety.rb
index 567ba00b0d..af46ae10d6 100644
--- a/activesupport/lib/active_support/core_ext/string/output_safety.rb
+++ b/activesupport/lib/active_support/core_ext/string/output_safety.rb
@@ -88,6 +88,14 @@ module ActiveSupport #:nodoc:
def to_s
self
end
+
+ def as_str
+ ''.replace(self)
+ end
+
+ def to_yaml(*args)
+ as_str.to_yaml(*args)
+ end
end
end
diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb
index 56de29b730..9c4412c28c 100644
--- a/activesupport/lib/active_support/dependencies.rb
+++ b/activesupport/lib/active_support/dependencies.rb
@@ -76,17 +76,19 @@ module ActiveSupport #:nodoc:
locked :concat, :each, :delete_if, :<<
def new_constants_for(frames)
- frames.map do |mod_name, prior_constants|
- mod = Inflector.constantize(mod_name)
+ constants = []
+ frames.each do |mod_name, prior_constants|
+ mod = Inflector.constantize(mod_name) if Dependencies.qualified_const_defined?(mod_name)
next unless mod.is_a?(Module)
new_constants = mod.local_constant_names - prior_constants
get(mod_name).concat(new_constants)
- new_constants.map do |suffix|
- ([mod_name, suffix] - ["Object"]).join("::")
+ new_constants.each do |suffix|
+ constants << ([mod_name, suffix] - ["Object"]).join("::")
end
- end.flatten
+ end
+ constants
end
# Add a set of modules to the watch stack, remembering the initial constants
@@ -115,8 +117,8 @@ module ActiveSupport #:nodoc:
def self.append_features(base)
base.class_eval do
# Emulate #exclude via an ivar
- return if @_const_missing
- @_const_missing = method(:const_missing)
+ return if defined?(@_const_missing) && @_const_missing
+ @_const_missing = instance_method(:const_missing)
remove_method(:const_missing)
end
super
@@ -177,6 +179,10 @@ module ActiveSupport #:nodoc:
end
def require_dependency(file_name, message = "No such file to load -- %s")
+ unless file_name.is_a?(String)
+ raise ArgumentError, "the file name must be a String -- you passed #{file_name.inspect}"
+ end
+
Dependencies.depend_on(file_name, false, message)
end
@@ -435,7 +441,10 @@ module ActiveSupport #:nodoc:
qualified_name = qualified_name_for from_mod, const_name
path_suffix = qualified_name.underscore
+
+ trace = caller.reject {|l| l =~ %r{#{Regexp.escape(__FILE__)}}}
name_error = NameError.new("uninitialized constant #{qualified_name}")
+ name_error.set_backtrace(trace)
file_path = search_for_file(path_suffix)
diff --git a/activesupport/lib/active_support/dependencies/autoload.rb b/activesupport/lib/active_support/dependencies/autoload.rb
index 44edb89ad5..f669f4a77e 100644
--- a/activesupport/lib/active_support/dependencies/autoload.rb
+++ b/activesupport/lib/active_support/dependencies/autoload.rb
@@ -1,7 +1,12 @@
require "active_support/inflector/methods"
+require "active_support/lazy_load_hooks"
module ActiveSupport
module Autoload
+ def self.extended(base)
+ base.extend(LazyLoadHooks)
+ end
+
@@autoloads = {}
@@under_path = nil
@@at_path = nil
diff --git a/activesupport/lib/active_support/deprecation/method_wrappers.rb b/activesupport/lib/active_support/deprecation/method_wrappers.rb
index cec8024b17..d0d8b577b3 100644
--- a/activesupport/lib/active_support/deprecation/method_wrappers.rb
+++ b/activesupport/lib/active_support/deprecation/method_wrappers.rb
@@ -12,15 +12,15 @@ module ActiveSupport
method_names.each do |method_name|
target_module.alias_method_chain(method_name, :deprecation) do |target, punctuation|
target_module.module_eval(<<-end_eval, __FILE__, __LINE__ + 1)
- def #{target}_with_deprecation#{punctuation}(*args, &block) # def generate_secret_with_deprecation(*args, &block)
- ::ActiveSupport::Deprecation.warn( # ::ActiveSupport::Deprecation.warn(
- ::ActiveSupport::Deprecation.deprecated_method_warning( # ::ActiveSupport::Deprecation.deprecated_method_warning(
- :#{method_name}, # :generate_secret,
- #{options[method_name].inspect}), # "You should use ActiveSupport::SecureRandom.hex(64)"),
- caller # caller
- ) # )
- send(:#{target}_without_deprecation#{punctuation}, *args, &block) # send(:generate_secret_without_deprecation, *args, &block)
- end # end
+ def #{target}_with_deprecation#{punctuation}(*args, &block)
+ ::ActiveSupport::Deprecation.warn(
+ ::ActiveSupport::Deprecation.deprecated_method_warning(
+ :#{method_name},
+ #{options[method_name].inspect}),
+ caller
+ )
+ send(:#{target}_without_deprecation#{punctuation}, *args, &block)
+ end
end_eval
end
end
diff --git a/activesupport/lib/active_support/deprecation/reporting.rb b/activesupport/lib/active_support/deprecation/reporting.rb
index fcb05ad8d9..03c445ffbf 100644
--- a/activesupport/lib/active_support/deprecation/reporting.rb
+++ b/activesupport/lib/active_support/deprecation/reporting.rb
@@ -29,7 +29,8 @@ module ActiveSupport
private
def deprecation_message(callstack, message = nil)
message ||= "You are using deprecated behavior which will be removed from the next major or minor release."
- "DEPRECATION WARNING: #{message}. #{deprecation_caller_message(callstack)}"
+ message += '.' unless message =~ /\.$/
+ "DEPRECATION WARNING: #{message} #{deprecation_caller_message(callstack)}"
end
def deprecation_caller_message(callstack)
diff --git a/activesupport/lib/active_support/i18n.rb b/activesupport/lib/active_support/i18n.rb
index 854c60eec1..034d7d8ddc 100644
--- a/activesupport/lib/active_support/i18n.rb
+++ b/activesupport/lib/active_support/i18n.rb
@@ -1,2 +1,3 @@
require 'i18n'
-I18n.load_path << "#{File.dirname(__FILE__)}/locale/en.yml" \ No newline at end of file
+I18n.load_path << "#{File.dirname(__FILE__)}/locale/en.yml"
+ActiveSupport.run_base_hooks(:i18n) \ No newline at end of file
diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb
index 41277893e3..c7df62e915 100644
--- a/activesupport/lib/active_support/inflector/methods.rb
+++ b/activesupport/lib/active_support/inflector/methods.rb
@@ -109,7 +109,7 @@ module ActiveSupport
constant = Object
names.each do |name|
- constant = constant.const_get(name, false) || constant.const_missing(name)
+ constant = constant.const_defined?(name, false) ? constant.const_get(name) : constant.const_missing(name)
end
constant
end
diff --git a/activesupport/lib/active_support/inflector/transliterate.rb b/activesupport/lib/active_support/inflector/transliterate.rb
index 30a9072ee1..236f2eb628 100644
--- a/activesupport/lib/active_support/inflector/transliterate.rb
+++ b/activesupport/lib/active_support/inflector/transliterate.rb
@@ -47,7 +47,7 @@ module ActiveSupport
# replace accented chars with their ascii equivalents
parameterized_string = transliterate(string)
# Turn unwanted chars into the separator
- parameterized_string.gsub!(/[^a-z0-9\-_\+]+/i, sep)
+ parameterized_string.gsub!(/[^a-z0-9\-_]+/i, sep)
unless sep.nil? || sep.empty?
re_sep = Regexp.escape(sep)
# No more than one of the separator in a row.
diff --git a/activesupport/lib/active_support/json/decoding.rb b/activesupport/lib/active_support/json/decoding.rb
index e357b6837a..04ff316a44 100644
--- a/activesupport/lib/active_support/json/decoding.rb
+++ b/activesupport/lib/active_support/json/decoding.rb
@@ -7,7 +7,7 @@ module ActiveSupport
module JSON
# Listed in order of preference.
- DECODERS = %w(Yajl JSONGem Yaml)
+ DECODERS = %w(Yajl Yaml)
class << self
attr_reader :parse_error
diff --git a/activesupport/lib/active_support/lazy_load_hooks.rb b/activesupport/lib/active_support/lazy_load_hooks.rb
new file mode 100644
index 0000000000..36acfda524
--- /dev/null
+++ b/activesupport/lib/active_support/lazy_load_hooks.rb
@@ -0,0 +1,25 @@
+module ActiveSupport
+ module LazyLoadHooks
+ def _setup_base_hooks
+ @base_hooks ||= Hash.new {|h,k| h[k] = [] }
+ @base ||= {}
+ end
+
+ def base_hook(name = nil, &block)
+ _setup_base_hooks
+
+ if base = @base[name]
+ base.instance_eval(&block)
+ else
+ @base_hooks[name] << block
+ end
+ end
+
+ def run_base_hooks(base, name = nil)
+ _setup_base_hooks
+
+ @base_hooks[name].each { |hook| base.instance_eval(&hook) } if @base_hooks
+ @base[name] = base
+ end
+ end
+end \ No newline at end of file
diff --git a/activesupport/lib/active_support/memoizable.rb b/activesupport/lib/active_support/memoizable.rb
index f810f53029..ca1cfedae3 100644
--- a/activesupport/lib/active_support/memoizable.rb
+++ b/activesupport/lib/active_support/memoizable.rb
@@ -1,4 +1,4 @@
-require 'active_support/core_ext/object/metaclass'
+require 'active_support/core_ext/object/singleton_class'
require 'active_support/core_ext/module/aliasing'
module ActiveSupport
diff --git a/activesupport/lib/active_support/notifications.rb b/activesupport/lib/active_support/notifications.rb
index 3e96decb8c..3f1fe64e9b 100644
--- a/activesupport/lib/active_support/notifications.rb
+++ b/activesupport/lib/active_support/notifications.rb
@@ -9,7 +9,7 @@ module ActiveSupport
# end
#
# You can consume those events and the information they provide by registering
- # a subscriber. For instance, let's store all instrumented events in an array:
+ # a log subscriber. For instance, let's store all instrumented events in an array:
#
# @events = []
#
@@ -35,7 +35,7 @@ module ActiveSupport
# end
#
# Notifications ships with a queue implementation that consumes and publish events
- # to subscribers in a thread. You can use any queue implementation you want.
+ # to log subscribers in a thread. You can use any queue implementation you want.
#
module Notifications
autoload :Instrumenter, 'active_support/notifications/instrumenter'
@@ -44,7 +44,7 @@ module ActiveSupport
class << self
attr_writer :notifier
- delegate :publish, :subscribe, :to => :notifier
+ delegate :publish, :subscribe, :unsubscribe, :to => :notifier
delegate :instrument, :to => :instrumenter
def notifier
@@ -69,6 +69,10 @@ module ActiveSupport
@queue.bind(pattern).subscribe(&block)
end
+ def unsubscribe(subscriber)
+ @queue.unsubscribe(subscriber)
+ end
+
def wait
@queue.wait
end
diff --git a/activesupport/lib/active_support/notifications/fanout.rb b/activesupport/lib/active_support/notifications/fanout.rb
index 0ec23da073..cd60054862 100644
--- a/activesupport/lib/active_support/notifications/fanout.rb
+++ b/activesupport/lib/active_support/notifications/fanout.rb
@@ -1,10 +1,11 @@
module ActiveSupport
module Notifications
# This is a default queue implementation that ships with Notifications. It
- # just pushes events to all registered subscribers.
+ # just pushes events to all registered log subscribers.
class Fanout
def initialize
@subscribers = []
+ @listeners_for = {}
end
def bind(pattern)
@@ -12,11 +13,22 @@ module ActiveSupport
end
def subscribe(pattern = nil, &block)
+ @listeners_for.clear
@subscribers << Subscriber.new(pattern, &block)
+ @subscribers.last
end
- def publish(*args)
- @subscribers.each { |s| s.publish(*args) }
+ def unsubscribe(subscriber)
+ @subscribers.delete(subscriber)
+ @listeners_for.clear
+ end
+
+ def publish(name, *args)
+ if listeners = @listeners_for[name]
+ listeners.each { |s| s.publish(name, *args) }
+ else
+ @listeners_for[name] = @subscribers.select { |s| s.publish(name, *args) }
+ end
end
# This is a sync queue, so there is not waiting.
@@ -48,7 +60,9 @@ module ActiveSupport
end
def publish(*args)
- push(*args) if matches?(args.first)
+ return unless matches?(args.first)
+ push(*args)
+ true
end
def drained?
diff --git a/activesupport/lib/active_support/ordered_options.rb b/activesupport/lib/active_support/ordered_options.rb
index 596a7b757d..61ccb79211 100644
--- a/activesupport/lib/active_support/ordered_options.rb
+++ b/activesupport/lib/active_support/ordered_options.rb
@@ -18,4 +18,10 @@ module ActiveSupport #:nodoc:
end
end
end
+
+ class InheritableOptions < OrderedOptions
+ def initialize(parent)
+ super() { |h,k| parent[k] }
+ end
+ end
end
diff --git a/activesupport/lib/active_support/railtie.rb b/activesupport/lib/active_support/railtie.rb
index c8d8b85000..d2c13e030d 100644
--- a/activesupport/lib/active_support/railtie.rb
+++ b/activesupport/lib/active_support/railtie.rb
@@ -33,14 +33,16 @@ module I18n
railtie_name :i18n
# Initialize I18n load paths to an array
- config.i18n.engines_load_path = []
+ config.i18n.railties_load_path = []
config.i18n.load_path = []
initializer "i18n.initialize" do
- require 'active_support/i18n'
-
- ActionDispatch::Callbacks.to_prepare do
+ ActiveSupport.base_hook(:i18n) do
I18n.reload!
+
+ ActionDispatch::Callbacks.to_prepare do
+ I18n.reload!
+ end
end
end
@@ -49,7 +51,7 @@ module I18n
config.after_initialize do |app|
app.config.i18n.each do |setting, value|
case setting
- when :engines_load_path
+ when :railties_load_path
app.config.i18n.load_path.unshift(*value)
when :load_path
I18n.load_path += value
diff --git a/activesupport/lib/active_support/ruby/shim.rb b/activesupport/lib/active_support/ruby/shim.rb
index 1e49ccdade..f0db5b3021 100644
--- a/activesupport/lib/active_support/ruby/shim.rb
+++ b/activesupport/lib/active_support/ruby/shim.rb
@@ -17,3 +17,4 @@ require 'active_support/core_ext/string/conversions'
require 'active_support/core_ext/string/interpolation'
require 'active_support/core_ext/rexml'
require 'active_support/core_ext/time/conversions'
+require 'active_support/core_ext/file/path'
diff --git a/activesupport/lib/active_support/version.rb b/activesupport/lib/active_support/version.rb
index 6c6187be29..831204693f 100644
--- a/activesupport/lib/active_support/version.rb
+++ b/activesupport/lib/active_support/version.rb
@@ -2,8 +2,9 @@ module ActiveSupport
module VERSION #:nodoc:
MAJOR = 3
MINOR = 0
- TINY = "0.beta1"
+ TINY = 0
+ BUILD = "beta1"
- STRING = [MAJOR, MINOR, TINY].join('.')
+ STRING = [MAJOR, MINOR, TINY, BUILD].join('.')
end
end
diff --git a/activesupport/lib/active_support/whiny_nil.rb b/activesupport/lib/active_support/whiny_nil.rb
index 11b05efac1..91ddef2619 100644
--- a/activesupport/lib/active_support/whiny_nil.rb
+++ b/activesupport/lib/active_support/whiny_nil.rb
@@ -25,17 +25,16 @@
# By default it is on in development and test modes, and it is off in production
# mode.
class NilClass
- WHINERS = [::Array]
- WHINERS << ::ActiveRecord::Base if defined? ::ActiveRecord
-
METHOD_CLASS_MAP = Hash.new
- WHINERS.each do |klass|
+ def self.add_whiner(klass)
methods = klass.public_instance_methods - public_instance_methods
class_name = klass.name
methods.each { |method| METHOD_CLASS_MAP[method.to_sym] = class_name }
end
+ add_whiner ::Array
+
# Raises a RuntimeError when you attempt to call +id+ on +nil+.
def id
raise RuntimeError, "Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id", caller