aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r--activesupport/lib/active_support/cache/mem_cache_store.rb5
-rw-r--r--activesupport/lib/active_support/core_ext/array/wrap.rb7
-rw-r--r--activesupport/lib/active_support/core_ext/date.rb7
-rw-r--r--activesupport/lib/active_support/core_ext/date/conversions.rb3
-rw-r--r--activesupport/lib/active_support/core_ext/date_time.rb5
-rw-r--r--activesupport/lib/active_support/core_ext/logger.rb4
-rw-r--r--activesupport/lib/active_support/core_ext/name_error.rb4
-rw-r--r--activesupport/lib/active_support/core_ext/string/interpolation.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/time.rb10
-rw-r--r--activesupport/lib/active_support/json/encoding.rb2
-rw-r--r--activesupport/lib/active_support/notifications.rb100
-rw-r--r--activesupport/lib/active_support/rescuable.rb2
-rw-r--r--activesupport/lib/active_support/testing/isolation.rb15
-rw-r--r--activesupport/lib/active_support/time.rb26
-rw-r--r--activesupport/lib/active_support/time_with_zone.rb8
-rw-r--r--activesupport/lib/active_support/values/time_zone.rb3
-rw-r--r--activesupport/lib/active_support/vendor.rb2
-rw-r--r--activesupport/lib/active_support/whiny_nil.rb10
18 files changed, 125 insertions, 90 deletions
diff --git a/activesupport/lib/active_support/cache/mem_cache_store.rb b/activesupport/lib/active_support/cache/mem_cache_store.rb
index bec9de86ed..1b6b820ca4 100644
--- a/activesupport/lib/active_support/cache/mem_cache_store.rb
+++ b/activesupport/lib/active_support/cache/mem_cache_store.rb
@@ -38,6 +38,11 @@ module ActiveSupport
#
# If no addresses are specified, then MemCacheStore will connect to
# localhost port 11211 (the default memcached port).
+ #
+ # Instead of addresses one can pass in a MemCache-like object. For example:
+ #
+ # require 'memcached' # gem install memcached; uses C bindings to libmemcached
+ # ActiveSupport::Cache::MemCacheStore.new(Memcached::Rails.new("localhost:11211"))
def initialize(*addresses)
if addresses.first.respond_to?(:get)
@data = addresses.first
diff --git a/activesupport/lib/active_support/core_ext/array/wrap.rb b/activesupport/lib/active_support/core_ext/array/wrap.rb
index 38bb68c1ec..f48d5ce500 100644
--- a/activesupport/lib/active_support/core_ext/array/wrap.rb
+++ b/activesupport/lib/active_support/core_ext/array/wrap.rb
@@ -4,11 +4,10 @@ class Array
def self.wrap(object)
if object.nil?
[]
- # to_a doesn't work correctly with Array() but to_ary always does
- elsif object.respond_to?(:to_a) && !object.respond_to?(:to_ary)
- [object]
+ elsif object.respond_to?(:to_ary)
+ object.to_ary
else
- Array(object)
+ [object]
end
end
end
diff --git a/activesupport/lib/active_support/core_ext/date.rb b/activesupport/lib/active_support/core_ext/date.rb
deleted file mode 100644
index 6672129076..0000000000
--- a/activesupport/lib/active_support/core_ext/date.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-require 'date'
-
-require 'active_support/core_ext/date/acts_like'
-require 'active_support/core_ext/date/freeze'
-
-require 'active_support/core_ext/date/calculations'
-require 'active_support/core_ext/date/conversions'
diff --git a/activesupport/lib/active_support/core_ext/date/conversions.rb b/activesupport/lib/active_support/core_ext/date/conversions.rb
index b41ad5b686..f6c870035b 100644
--- a/activesupport/lib/active_support/core_ext/date/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/date/conversions.rb
@@ -1,7 +1,4 @@
require 'active_support/inflector'
-require 'active_support/core_ext/time/conversions'
-require 'active_support/core_ext/date_time/conversions'
-require 'active_support/values/time_zone'
class Date
DATE_FORMATS = {
diff --git a/activesupport/lib/active_support/core_ext/date_time.rb b/activesupport/lib/active_support/core_ext/date_time.rb
deleted file mode 100644
index 004fd0ad29..0000000000
--- a/activesupport/lib/active_support/core_ext/date_time.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-require 'active_support/core_ext/time'
-require 'active_support/core_ext/date_time/acts_like'
-require 'active_support/core_ext/date_time/calculations'
-require 'active_support/core_ext/date_time/conversions'
-require 'active_support/core_ext/date_time/zones'
diff --git a/activesupport/lib/active_support/core_ext/logger.rb b/activesupport/lib/active_support/core_ext/logger.rb
index 22749229a3..e4df8fe338 100644
--- a/activesupport/lib/active_support/core_ext/logger.rb
+++ b/activesupport/lib/active_support/core_ext/logger.rb
@@ -137,10 +137,10 @@ class Logger
attr_writer :formatter
public :formatter=
- alias old_format_datetime format_datetime
+ alias old_format_datetime format_datetime if method_defined?(:format_datetime)
def format_datetime(datetime) datetime end
- alias old_msg2str msg2str
+ alias old_msg2str msg2str if method_defined?(:msg2str)
def msg2str(msg) msg end
end
end
diff --git a/activesupport/lib/active_support/core_ext/name_error.rb b/activesupport/lib/active_support/core_ext/name_error.rb
index cd165626c8..e1ebd4f91c 100644
--- a/activesupport/lib/active_support/core_ext/name_error.rb
+++ b/activesupport/lib/active_support/core_ext/name_error.rb
@@ -1,7 +1,9 @@
class NameError
# Extract the name of the missing constant from the exception message.
def missing_name
- $1 if /((::)?([A-Z]\w*)(::[A-Z]\w*)*)$/ =~ message
+ if /undefined local variable or method/ !~ message
+ $1 if /((::)?([A-Z]\w*)(::[A-Z]\w*)*)$/ =~ message
+ end
end
# Was this exception raised because the given name was missing?
diff --git a/activesupport/lib/active_support/core_ext/string/interpolation.rb b/activesupport/lib/active_support/core_ext/string/interpolation.rb
index 41a061c1a4..2048d35091 100644
--- a/activesupport/lib/active_support/core_ext/string/interpolation.rb
+++ b/activesupport/lib/active_support/core_ext/string/interpolation.rb
@@ -5,7 +5,7 @@
You may redistribute it and/or modify it under the same license terms as Ruby.
=end
-if RUBY_VERSION < '1.9'
+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
diff --git a/activesupport/lib/active_support/core_ext/time.rb b/activesupport/lib/active_support/core_ext/time.rb
deleted file mode 100644
index b28f7f1a32..0000000000
--- a/activesupport/lib/active_support/core_ext/time.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-require 'date'
-require 'time'
-
-require 'active_support/core_ext/time/publicize_conversion_methods'
-require 'active_support/core_ext/time/marshal_with_utc_flag'
-
-require 'active_support/core_ext/time/acts_like'
-require 'active_support/core_ext/time/calculations'
-require 'active_support/core_ext/time/conversions'
-require 'active_support/core_ext/time/zones'
diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb
index 8e8f9022c1..3c15056c41 100644
--- a/activesupport/lib/active_support/json/encoding.rb
+++ b/activesupport/lib/active_support/json/encoding.rb
@@ -6,7 +6,7 @@ require 'active_support/core_ext/module/delegation'
require 'active_support/core_ext/object/instance_variables'
require 'active_support/deprecation'
-require 'active_support/time_with_zone'
+require 'active_support/time'
# Hack to load json gem first so we can overwrite its to_json.
begin
diff --git a/activesupport/lib/active_support/notifications.rb b/activesupport/lib/active_support/notifications.rb
index 6304f496f5..e2540cd598 100644
--- a/activesupport/lib/active_support/notifications.rb
+++ b/activesupport/lib/active_support/notifications.rb
@@ -41,7 +41,7 @@ module ActiveSupport
# to subscribers in a thread. You can use any queue implementation you want.
#
module Notifications
- mattr_accessor :queue
+ mattr_accessor :queue, :listener
class << self
delegate :instrument, :transaction_id, :transaction, :to => :instrumenter
@@ -54,8 +54,13 @@ module ActiveSupport
@publisher ||= Publisher.new(queue)
end
- def subscribe(pattern=nil, &block)
- Subscriber.new(queue).bind(pattern).subscribe(&block)
+ def subscriber
+ @subscriber ||= Subscriber.new(queue)
+ end
+
+ def subscribe(pattern=nil, options={}, &block)
+ with = options[:with] || listener
+ subscriber.bind(with, pattern).subscribe(&block)
end
end
@@ -104,13 +109,14 @@ module ActiveSupport
@queue = queue
end
- def bind(pattern)
- @pattern = pattern
+ def bind(listener, pattern)
+ @listener = listener
+ @pattern = pattern
self
end
def subscribe
- @queue.subscribe(@pattern) do |*args|
+ @queue.subscribe(@listener, @pattern) do |*args|
yield(*args)
end
end
@@ -138,54 +144,70 @@ module ActiveSupport
end
end
- # This is a default queue implementation that ships with Notifications. It
- # consumes events in a thread and publish them to all registered subscribers.
- #
- class LittleFanout
- def initialize
- @listeners = []
- @stream = Queue.new
+ class AsyncListener
+ def initialize(pattern, &block)
+ @pattern = pattern
+ @subscriber = block
+ @queue = Queue.new
Thread.new { consume }
end
- def publish(*args)
- @stream.push(args)
- end
-
- def subscribe(pattern=nil, &block)
- @listeners << Listener.new(pattern, &block)
+ def publish(name, *args)
+ if !@pattern || @pattern === name.to_s
+ @queue << args.unshift(name)
+ end
end
def consume
- while args = @stream.shift
- @listeners.each { |l| l.publish(*args) }
+ while args = @queue.shift
+ @subscriber.call(*args)
end
end
- class Listener
- # attr_reader :thread
+ def drained?
+ @queue.size.zero?
+ end
+ end
- def initialize(pattern, &block)
- @pattern = pattern
- @subscriber = block
- @queue = Queue.new
- Thread.new { consume }
- end
+ class SyncListener
+ def initialize(pattern, &block)
+ @pattern = pattern
+ @subscriber = block
+ end
- def publish(name, *args)
- if !@pattern || @pattern === name.to_s
- @queue << args.unshift(name)
- end
+ def publish(name, *args)
+ if !@pattern || @pattern === name.to_s
+ @subscriber.call(*args.unshift(name))
end
+ end
- def consume
- while args = @queue.shift
- @subscriber.call(*args)
- end
- end
+ def drained?
+ true
+ end
+ end
+
+ # This is a default queue implementation that ships with Notifications. It
+ # consumes events in a thread and publish them to all registered subscribers.
+ #
+ class LittleFanout
+ def initialize
+ @listeners = []
+ end
+
+ def publish(*args)
+ @listeners.each { |l| l.publish(*args) }
+ end
+
+ def subscribe(listener, pattern=nil, &block)
+ @listeners << listener.new(pattern, &block)
+ end
+
+ def drained?
+ @listeners.all? &:drained?
end
end
end
- Notifications.queue = Notifications::LittleFanout.new
+ Notifications.queue = Notifications::LittleFanout.new
+ Notifications.listener = Notifications::AsyncListener
end
diff --git a/activesupport/lib/active_support/rescuable.rb b/activesupport/lib/active_support/rescuable.rb
index 879662c16c..f0119f5994 100644
--- a/activesupport/lib/active_support/rescuable.rb
+++ b/activesupport/lib/active_support/rescuable.rb
@@ -81,7 +81,7 @@ module ActiveSupport
def handler_for_rescue(exception)
# We go from right to left because pairs are pushed onto rescue_handlers
# as rescue_from declarations are found.
- _, rescuer = Array(rescue_handlers).reverse.detect do |klass_name, handler|
+ _, rescuer = rescue_handlers.reverse.detect do |klass_name, handler|
# The purpose of allowing strings in rescue_from is to support the
# declaration of handler associations for exception classes whose
# definition is yet unknown.
diff --git a/activesupport/lib/active_support/testing/isolation.rb b/activesupport/lib/active_support/testing/isolation.rb
index c75b59c284..81f7e3c9df 100644
--- a/activesupport/lib/active_support/testing/isolation.rb
+++ b/activesupport/lib/active_support/testing/isolation.rb
@@ -1,10 +1,25 @@
module ActiveSupport
module Testing
+ class RemoteError < StandardError
+
+ attr_reader :message, :backtrace
+
+ def initialize(exception)
+ @message = "caught #{exception.class.name}: #{exception.message}"
+ @backtrace = exception.backtrace
+ end
+ end
+
class ProxyTestResult
def initialize
@calls = []
end
+ def add_error(e)
+ e = Test::Unit::Error.new(e.test_name, RemoteError.new(e.exception))
+ @calls << [:add_error, e]
+ end
+
def __replay__(result)
@calls.each do |name, args|
result.send(name, *args)
diff --git a/activesupport/lib/active_support/time.rb b/activesupport/lib/active_support/time.rb
index d36a683601..0f421421d0 100644
--- a/activesupport/lib/active_support/time.rb
+++ b/activesupport/lib/active_support/time.rb
@@ -1,7 +1,4 @@
require 'active_support'
-require 'active_support/core_ext/time'
-require 'active_support/core_ext/date'
-require 'active_support/core_ext/date_time'
module ActiveSupport
autoload :Duration, 'active_support/duration'
@@ -12,3 +9,26 @@ module ActiveSupport
[Duration, TimeWithZone, TimeZone]
end
end
+
+require 'date'
+require 'time'
+
+require 'active_support/core_ext/time/publicize_conversion_methods'
+require 'active_support/core_ext/time/marshal_with_utc_flag'
+require 'active_support/core_ext/time/acts_like'
+require 'active_support/core_ext/time/calculations'
+require 'active_support/core_ext/time/conversions'
+require 'active_support/core_ext/time/zones'
+
+require 'active_support/core_ext/date/acts_like'
+require 'active_support/core_ext/date/freeze'
+require 'active_support/core_ext/date/calculations'
+require 'active_support/core_ext/date/conversions'
+
+require 'active_support/core_ext/date_time/acts_like'
+require 'active_support/core_ext/date_time/calculations'
+require 'active_support/core_ext/date_time/conversions'
+require 'active_support/core_ext/date_time/zones'
+
+require 'active_support/core_ext/integer/time'
+require 'active_support/core_ext/numeric/time'
diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb
index a64128e49e..8304f6c434 100644
--- a/activesupport/lib/active_support/time_with_zone.rb
+++ b/activesupport/lib/active_support/time_with_zone.rb
@@ -1,10 +1,4 @@
-require 'active_support/duration'
-require 'active_support/values/time_zone'
-require 'active_support/core_ext/numeric/time'
-require 'active_support/core_ext/integer/time'
-require 'active_support/core_ext/time/conversions'
-require 'active_support/core_ext/date/conversions'
-require 'active_support/core_ext/date_time/conversions'
+require "active_support/values/time_zone"
module ActiveSupport
# A Time-like class that can represent a time in any time zone. Necessary because standard Ruby Time instances are
diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb
index e7583bef1b..cbb8e890ae 100644
--- a/activesupport/lib/active_support/values/time_zone.rb
+++ b/activesupport/lib/active_support/values/time_zone.rb
@@ -1,7 +1,4 @@
require 'active_support/core_ext/object/blank'
-require 'active_support/core_ext/time'
-require 'active_support/core_ext/date'
-require 'active_support/core_ext/date_time'
# The TimeZone class serves as a wrapper around TZInfo::Timezone instances. It allows us to do the following:
#
diff --git a/activesupport/lib/active_support/vendor.rb b/activesupport/lib/active_support/vendor.rb
index 4a711b7e25..eb5080888c 100644
--- a/activesupport/lib/active_support/vendor.rb
+++ b/activesupport/lib/active_support/vendor.rb
@@ -9,7 +9,7 @@ end
unless ActiveSupport.requirable? lib
# Try to activate a gem ~> satisfying the requested version first.
begin
- gem lib, "~> #{version}"
+ gem lib, ">= #{version}"
# Use the vendored lib if the gem's missing or we aren't using RubyGems.
rescue LoadError, NoMethodError
# There could be symlinks
diff --git a/activesupport/lib/active_support/whiny_nil.rb b/activesupport/lib/active_support/whiny_nil.rb
index 36fe9510ba..c4aaba7ab3 100644
--- a/activesupport/lib/active_support/whiny_nil.rb
+++ b/activesupport/lib/active_support/whiny_nil.rb
@@ -43,7 +43,14 @@ class NilClass
private
def method_missing(method, *args, &block)
- raise_nil_warning_for METHOD_CLASS_MAP[method], method, caller
+ # Ruby 1.9.2: disallow explicit coercion via method_missing.
+ if method == :to_ary || method == :to_str
+ super
+ elsif klass = METHOD_CLASS_MAP[method]
+ raise_nil_warning_for klass, method, caller
+ else
+ super
+ end
end
# Raises a NoMethodError when you attempt to call a method on +nil+.
@@ -55,4 +62,3 @@ class NilClass
raise NoMethodError, message, with_caller || caller
end
end
-