aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support.rb34
-rw-r--r--activesupport/lib/active_support/all.rb3
-rw-r--r--activesupport/lib/active_support/autoload.rb25
-rw-r--r--activesupport/lib/active_support/cache/mem_cache_store.rb2
-rw-r--r--activesupport/lib/active_support/core.rb7
-rw-r--r--activesupport/lib/active_support/core/all.rb5
-rw-r--r--activesupport/lib/active_support/core/time.rb4
-rw-r--r--activesupport/lib/active_support/core_ext/hash/conversions.rb3
-rw-r--r--activesupport/lib/active_support/core_ext/object/misc.rb83
-rw-r--r--activesupport/lib/active_support/core_ext/object/returning.rb42
-rw-r--r--activesupport/lib/active_support/core_ext/object/tap.rb16
-rw-r--r--activesupport/lib/active_support/core_ext/object/with_options.rb24
-rw-r--r--activesupport/lib/active_support/core_ext/symbol.rb15
-rw-r--r--activesupport/lib/active_support/core_ext/symbol/to_proc.rb14
-rw-r--r--activesupport/lib/active_support/dependency_module.rb10
-rw-r--r--activesupport/lib/active_support/json.rb4
-rw-r--r--activesupport/lib/active_support/new_callbacks.rb28
-rw-r--r--activesupport/lib/active_support/ruby/shim.rb24
-rw-r--r--activesupport/lib/active_support/test_case.rb5
-rw-r--r--activesupport/lib/active_support/testing/pending.rb5
-rw-r--r--activesupport/lib/active_support/time.rb14
-rw-r--r--activesupport/lib/active_support/time/autoload.rb (renamed from activesupport/lib/active_support/core/time/autoload.rb)0
22 files changed, 221 insertions, 146 deletions
diff --git a/activesupport/lib/active_support.rb b/activesupport/lib/active_support.rb
index dab017770d..a20635ba62 100644
--- a/activesupport/lib/active_support.rb
+++ b/activesupport/lib/active_support.rb
@@ -22,35 +22,19 @@
#++
module ActiveSupport
- def self.load_all!
- [Dependencies, Deprecation, Gzip, MessageVerifier, Multibyte, SecureRandom] + Core.load_all!
+ class << self
+ attr_accessor :load_all_hooks
+ def on_load_all(&hook) load_all_hooks << hook end
+ def load_all!; load_all_hooks.each { |hook| hook.call } end
end
+ self.load_all_hooks = []
- autoload :BacktraceCleaner, 'active_support/backtrace_cleaner'
- autoload :Base64, 'active_support/base64'
- autoload :BasicObject, 'active_support/basic_object'
- autoload :BufferedLogger, 'active_support/buffered_logger'
- autoload :Cache, 'active_support/cache'
- autoload :Callbacks, 'active_support/callbacks'
- autoload :NewCallbacks, 'active_support/new_callbacks'
- autoload :ConcurrentHash, 'active_support/concurrent_hash'
- autoload :DependencyModule, 'active_support/dependency_module'
- autoload :Deprecation, 'active_support/deprecation'
- autoload :Gzip, 'active_support/gzip'
- autoload :Inflector, 'active_support/inflector'
- autoload :Memoizable, 'active_support/memoizable'
- autoload :MessageEncryptor, 'active_support/message_encryptor'
- autoload :MessageVerifier, 'active_support/message_verifier'
- autoload :Multibyte, 'active_support/multibyte'
- autoload :OptionMerger, 'active_support/option_merger'
- autoload :OrderedHash, 'active_support/ordered_hash'
- autoload :OrderedOptions, 'active_support/ordered_options'
- autoload :Rescuable, 'active_support/rescuable'
- autoload :SecureRandom, 'active_support/secure_random'
- autoload :StringInquirer, 'active_support/string_inquirer'
- autoload :XmlMini, 'active_support/xml_mini'
+ on_load_all do
+ [Dependencies, Deprecation, Gzip, MessageVerifier, Multibyte, SecureRandom]
+ end
end
+require 'active_support/autoload'
require 'active_support/vendor'
I18n.load_path << "#{File.dirname(__FILE__)}/active_support/locale/en.yml"
diff --git a/activesupport/lib/active_support/all.rb b/activesupport/lib/active_support/all.rb
new file mode 100644
index 0000000000..f537818300
--- /dev/null
+++ b/activesupport/lib/active_support/all.rb
@@ -0,0 +1,3 @@
+require 'active_support'
+require 'active_support/time'
+require 'active_support/core_ext'
diff --git a/activesupport/lib/active_support/autoload.rb b/activesupport/lib/active_support/autoload.rb
new file mode 100644
index 0000000000..ed229d1c5f
--- /dev/null
+++ b/activesupport/lib/active_support/autoload.rb
@@ -0,0 +1,25 @@
+module ActiveSupport
+ autoload :BacktraceCleaner, 'active_support/backtrace_cleaner'
+ autoload :Base64, 'active_support/base64'
+ autoload :BasicObject, 'active_support/basic_object'
+ autoload :BufferedLogger, 'active_support/buffered_logger'
+ autoload :Cache, 'active_support/cache'
+ autoload :Callbacks, 'active_support/callbacks'
+ autoload :NewCallbacks, 'active_support/new_callbacks'
+ autoload :ConcurrentHash, 'active_support/concurrent_hash'
+ autoload :DependencyModule, 'active_support/dependency_module'
+ autoload :Deprecation, 'active_support/deprecation'
+ autoload :Gzip, 'active_support/gzip'
+ autoload :Inflector, 'active_support/inflector'
+ autoload :Memoizable, 'active_support/memoizable'
+ autoload :MessageEncryptor, 'active_support/message_encryptor'
+ autoload :MessageVerifier, 'active_support/message_verifier'
+ autoload :Multibyte, 'active_support/multibyte'
+ autoload :OptionMerger, 'active_support/option_merger'
+ autoload :OrderedHash, 'active_support/ordered_hash'
+ autoload :OrderedOptions, 'active_support/ordered_options'
+ autoload :Rescuable, 'active_support/rescuable'
+ autoload :SecureRandom, 'active_support/secure_random'
+ autoload :StringInquirer, 'active_support/string_inquirer'
+ autoload :XmlMini, 'active_support/xml_mini'
+end
diff --git a/activesupport/lib/active_support/cache/mem_cache_store.rb b/activesupport/lib/active_support/cache/mem_cache_store.rb
index ab8eb72096..38b3409ca6 100644
--- a/activesupport/lib/active_support/cache/mem_cache_store.rb
+++ b/activesupport/lib/active_support/cache/mem_cache_store.rb
@@ -39,7 +39,7 @@ module ActiveSupport
# If no addresses are specified, then MemCacheStore will connect to
# localhost port 11211 (the default memcached port).
def initialize(*addresses)
- if addresses.first.is_a?(MemCache)
+ if addresses.first.respond_to?(:get)
@data = addresses.first
else
@data = self.class.build_mem_cache(*addresses)
diff --git a/activesupport/lib/active_support/core.rb b/activesupport/lib/active_support/core.rb
deleted file mode 100644
index ad8db94941..0000000000
--- a/activesupport/lib/active_support/core.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-module ActiveSupport
- module Core
- def self.load_all!
- [TimeWithZone]
- end
- end
-end
diff --git a/activesupport/lib/active_support/core/all.rb b/activesupport/lib/active_support/core/all.rb
deleted file mode 100644
index 55e8b4cfac..0000000000
--- a/activesupport/lib/active_support/core/all.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-require 'active_support/core_ext'
-require 'active_support/core'
-Dir["#{File.dirname(__FILE__)}/*.rb"].sort.each do |path|
- require "active_support/core/#{File.basename(path, '.rb')}"
-end
diff --git a/activesupport/lib/active_support/core/time.rb b/activesupport/lib/active_support/core/time.rb
deleted file mode 100644
index 43e13b5e58..0000000000
--- a/activesupport/lib/active_support/core/time.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-require 'active_support/core/time/autoload'
-require 'active_support/core_ext/time'
-require 'active_support/core_ext/date'
-require 'active_support/core_ext/date_time'
diff --git a/activesupport/lib/active_support/core_ext/hash/conversions.rb b/activesupport/lib/active_support/core_ext/hash/conversions.rb
index fe1f79050c..2a34874d08 100644
--- a/activesupport/lib/active_support/core_ext/hash/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/hash/conversions.rb
@@ -1,8 +1,7 @@
-require 'date'
+require 'active_support/time'
require 'active_support/core_ext/object/conversions'
require 'active_support/core_ext/array/conversions'
require 'active_support/core_ext/hash/reverse_merge'
-require 'active_support/core/time'
class Hash
# This module exists to decorate files deserialized using Hash.from_xml with
diff --git a/activesupport/lib/active_support/core_ext/object/misc.rb b/activesupport/lib/active_support/core_ext/object/misc.rb
index fb1bcdb98f..80011dfbed 100644
--- a/activesupport/lib/active_support/core_ext/object/misc.rb
+++ b/activesupport/lib/active_support/core_ext/object/misc.rb
@@ -1,80 +1,3 @@
-class Object
- # Returns +value+ after yielding +value+ to the block. This simplifies the
- # process of constructing an object, performing work on the object, and then
- # returning the object from a method. It is a Ruby-ized realization of the K
- # combinator, courtesy of Mikael Brockman.
- #
- # ==== Examples
- #
- # # Without returning
- # def foo
- # values = []
- # values << "bar"
- # values << "baz"
- # return values
- # end
- #
- # foo # => ['bar', 'baz']
- #
- # # returning with a local variable
- # def foo
- # returning values = [] do
- # values << 'bar'
- # values << 'baz'
- # end
- # end
- #
- # foo # => ['bar', 'baz']
- #
- # # returning with a block argument
- # def foo
- # returning [] do |values|
- # values << 'bar'
- # values << 'baz'
- # end
- # end
- #
- # foo # => ['bar', 'baz']
- def returning(value)
- yield(value)
- value
- end
-
- # Yields <code>x</code> to the block, and then returns <code>x</code>.
- # The primary purpose of this method is to "tap into" a method chain,
- # in order to perform operations on intermediate results within the chain.
- #
- # (1..10).tap { |x| puts "original: #{x.inspect}" }.to_a.
- # tap { |x| puts "array: #{x.inspect}" }.
- # select { |x| x%2 == 0 }.
- # tap { |x| puts "evens: #{x.inspect}" }.
- # map { |x| x*x }.
- # tap { |x| puts "squares: #{x.inspect}" }
- def tap
- yield self
- self
- end unless Object.respond_to?(:tap)
-
- # An elegant way to factor duplication out of options passed to a series of
- # method calls. Each method called in the block, with the block variable as
- # the receiver, will have its options merged with the default +options+ hash
- # provided. Each method called on the block variable must take an options
- # hash as its final argument.
- #
- # with_options :order => 'created_at', :class_name => 'Comment' do |post|
- # post.has_many :comments, :conditions => ['approved = ?', true], :dependent => :delete_all
- # post.has_many :unapproved_comments, :conditions => ['approved = ?', false]
- # post.has_many :all_comments
- # end
- #
- # Can also be used with an explicit receiver:
- #
- # map.with_options :controller => "people" do |people|
- # people.connect "/people", :action => "index"
- # people.connect "/people/:id", :action => "show"
- # end
- #
- def with_options(options)
- yield ActiveSupport::OptionMerger.new(self, options)
- end
-end
+require 'active_support/core_ext/object/returning'
+require 'active_support/core_ext/object/tap'
+require 'active_support/core_ext/object/with_options'
diff --git a/activesupport/lib/active_support/core_ext/object/returning.rb b/activesupport/lib/active_support/core_ext/object/returning.rb
new file mode 100644
index 0000000000..0dc2e1266a
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/object/returning.rb
@@ -0,0 +1,42 @@
+class Object
+ # Returns +value+ after yielding +value+ to the block. This simplifies the
+ # process of constructing an object, performing work on the object, and then
+ # returning the object from a method. It is a Ruby-ized realization of the K
+ # combinator, courtesy of Mikael Brockman.
+ #
+ # ==== Examples
+ #
+ # # Without returning
+ # def foo
+ # values = []
+ # values << "bar"
+ # values << "baz"
+ # return values
+ # end
+ #
+ # foo # => ['bar', 'baz']
+ #
+ # # returning with a local variable
+ # def foo
+ # returning values = [] do
+ # values << 'bar'
+ # values << 'baz'
+ # end
+ # end
+ #
+ # foo # => ['bar', 'baz']
+ #
+ # # returning with a block argument
+ # def foo
+ # returning [] do |values|
+ # values << 'bar'
+ # values << 'baz'
+ # end
+ # end
+ #
+ # foo # => ['bar', 'baz']
+ def returning(value)
+ yield(value)
+ value
+ end
+end
diff --git a/activesupport/lib/active_support/core_ext/object/tap.rb b/activesupport/lib/active_support/core_ext/object/tap.rb
new file mode 100644
index 0000000000..db7e715e2d
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/object/tap.rb
@@ -0,0 +1,16 @@
+class Object
+ # Yields <code>x</code> to the block, and then returns <code>x</code>.
+ # The primary purpose of this method is to "tap into" a method chain,
+ # in order to perform operations on intermediate results within the chain.
+ #
+ # (1..10).tap { |x| puts "original: #{x.inspect}" }.to_a.
+ # tap { |x| puts "array: #{x.inspect}" }.
+ # select { |x| x%2 == 0 }.
+ # tap { |x| puts "evens: #{x.inspect}" }.
+ # map { |x| x*x }.
+ # tap { |x| puts "squares: #{x.inspect}" }
+ def tap
+ yield self
+ self
+ end unless Object.respond_to?(:tap)
+end
diff --git a/activesupport/lib/active_support/core_ext/object/with_options.rb b/activesupport/lib/active_support/core_ext/object/with_options.rb
new file mode 100644
index 0000000000..dd38b7d261
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/object/with_options.rb
@@ -0,0 +1,24 @@
+class Object
+ # An elegant way to factor duplication out of options passed to a series of
+ # method calls. Each method called in the block, with the block variable as
+ # the receiver, will have its options merged with the default +options+ hash
+ # provided. Each method called on the block variable must take an options
+ # hash as its final argument.
+ #
+ # with_options :order => 'created_at', :class_name => 'Comment' do |post|
+ # post.has_many :comments, :conditions => ['approved = ?', true], :dependent => :delete_all
+ # post.has_many :unapproved_comments, :conditions => ['approved = ?', false]
+ # post.has_many :all_comments
+ # end
+ #
+ # Can also be used with an explicit receiver:
+ #
+ # map.with_options :controller => "people" do |people|
+ # people.connect "/people", :action => "index"
+ # people.connect "/people/:id", :action => "show"
+ # end
+ #
+ def with_options(options)
+ yield ActiveSupport::OptionMerger.new(self, options)
+ end
+end
diff --git a/activesupport/lib/active_support/core_ext/symbol.rb b/activesupport/lib/active_support/core_ext/symbol.rb
index 520369452b..c103cd9dcf 100644
--- a/activesupport/lib/active_support/core_ext/symbol.rb
+++ b/activesupport/lib/active_support/core_ext/symbol.rb
@@ -1,14 +1 @@
-class Symbol
- # Turns the symbol into a simple proc, which is especially useful for enumerations. Examples:
- #
- # # The same as people.collect { |p| p.name }
- # people.collect(&:name)
- #
- # # The same as people.select { |p| p.manager? }.collect { |p| p.salary }
- # people.select(&:manager?).collect(&:salary)
- #
- # This is a builtin method in Ruby 1.8.7 and later.
- def to_proc
- Proc.new { |*args| args.shift.__send__(self, *args) }
- end unless :to_proc.respond_to?(:to_proc)
-end
+require 'active_support/core_ext/symbol/to_proc'
diff --git a/activesupport/lib/active_support/core_ext/symbol/to_proc.rb b/activesupport/lib/active_support/core_ext/symbol/to_proc.rb
new file mode 100644
index 0000000000..520369452b
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/symbol/to_proc.rb
@@ -0,0 +1,14 @@
+class Symbol
+ # Turns the symbol into a simple proc, which is especially useful for enumerations. Examples:
+ #
+ # # The same as people.collect { |p| p.name }
+ # people.collect(&:name)
+ #
+ # # The same as people.select { |p| p.manager? }.collect { |p| p.salary }
+ # people.select(&:manager?).collect(&:salary)
+ #
+ # This is a builtin method in Ruby 1.8.7 and later.
+ def to_proc
+ Proc.new { |*args| args.shift.__send__(self, *args) }
+ end unless :to_proc.respond_to?(:to_proc)
+end
diff --git a/activesupport/lib/active_support/dependency_module.rb b/activesupport/lib/active_support/dependency_module.rb
index 8c202acc8f..9872b9654b 100644
--- a/activesupport/lib/active_support/dependency_module.rb
+++ b/activesupport/lib/active_support/dependency_module.rb
@@ -16,10 +16,12 @@ module ActiveSupport
end
end
- def depends_on(mod)
- return if self < mod
- @_dependencies ||= []
- @_dependencies << mod
+ def depends_on(*mods)
+ mods.each do |mod|
+ next if self < mod
+ @_dependencies ||= []
+ @_dependencies << mod
+ end
end
end
end
diff --git a/activesupport/lib/active_support/json.rb b/activesupport/lib/active_support/json.rb
index 1e8ded12da..6d845182fb 100644
--- a/activesupport/lib/active_support/json.rb
+++ b/activesupport/lib/active_support/json.rb
@@ -43,10 +43,10 @@ module ActiveSupport
delegate :decode, :to => :backend
def backend
- @backend || begin
+ unless defined? @backend
self.backend = defined?(::JSON) ? "JSONGem" : "Yaml"
- @backend
end
+ @backend
end
def backend=(name)
diff --git a/activesupport/lib/active_support/new_callbacks.rb b/activesupport/lib/active_support/new_callbacks.rb
index 9316d6d2b6..b6cbdbb6b0 100644
--- a/activesupport/lib/active_support/new_callbacks.rb
+++ b/activesupport/lib/active_support/new_callbacks.rb
@@ -287,6 +287,14 @@ module ActiveSupport
when Proc
@klass.send(:define_method, method_name, &filter)
method_name << (filter.arity == 1 ? "(self)" : "")
+ when Method
+ @klass.send(:define_method, "#{method_name}_method") { filter }
+ @klass.class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
+ def #{method_name}(&blk)
+ #{method_name}_method.call(self, &blk)
+ end
+ RUBY_EVAL
+ method_name
when String
@klass.class_eval <<-RUBY_EVAL
def #{method_name}
@@ -296,8 +304,24 @@ module ActiveSupport
method_name
else
kind, name = @kind, @name
- @klass.send(:define_method, method_name) do
- filter.send("#{kind}_#{name}", self)
+ @klass.send(:define_method, "#{method_name}_object") { filter }
+
+ if kind == :around
+ @klass.class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
+ def #{method_name}(&blk)
+ if :#{kind} == :around && #{method_name}_object.respond_to?(:filter)
+ #{method_name}_object.send("filter", self, &blk)
+ else
+ #{method_name}_object.send("#{kind}_#{name}", self, &blk)
+ end
+ end
+ RUBY_EVAL
+ else
+ @klass.class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
+ def #{method_name}(&blk)
+ #{method_name}_object.send("#{kind}_#{name}", self, &blk)
+ end
+ RUBY_EVAL
end
method_name
end
diff --git a/activesupport/lib/active_support/ruby/shim.rb b/activesupport/lib/active_support/ruby/shim.rb
new file mode 100644
index 0000000000..37c57c485a
--- /dev/null
+++ b/activesupport/lib/active_support/ruby/shim.rb
@@ -0,0 +1,24 @@
+# Backported Ruby builtins so you can code with the latest & greatest
+# but still run on any Ruby 1.8.x.
+#
+# Date next_year, next_month
+# DateTime to_date, to_datetime, xmlschema
+# Enumerable group_by, each_with_object, none?
+# Integer even?, odd?
+# Object tap
+# Process Process.daemon
+# REXML security fix
+# String ord
+# Symbol to_proc
+# Time to_date, to_time, to_datetime
+require 'active_support'
+require 'active_support/core_ext/date/calculations'
+require 'active_support/core_ext/date_time/conversions'
+require 'active_support/core_ext/enumerable'
+require 'active_support/core_ext/integer/even_odd'
+require 'active_support/core_ext/object/tap'
+require 'active_support/core_ext/process/daemon'
+require 'active_support/core_ext/string/conversions'
+require 'active_support/core_ext/rexml'
+require 'active_support/core_ext/symbol/to_proc'
+require 'active_support/core_ext/time/conversions'
diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb
index 50e25ef740..bab2a401eb 100644
--- a/activesupport/lib/active_support/test_case.rb
+++ b/activesupport/lib/active_support/test_case.rb
@@ -32,6 +32,11 @@ module ActiveSupport
include ActiveSupport::Testing::Default
end
+ $tags = {}
+ def self.for_tag(tag)
+ yield if $tags[tag]
+ end
+
include ActiveSupport::Testing::SetupAndTeardown
include ActiveSupport::Testing::Assertions
include ActiveSupport::Testing::Deprecation
diff --git a/activesupport/lib/active_support/testing/pending.rb b/activesupport/lib/active_support/testing/pending.rb
index d945c7e476..21134ff9e2 100644
--- a/activesupport/lib/active_support/testing/pending.rb
+++ b/activesupport/lib/active_support/testing/pending.rb
@@ -11,6 +11,11 @@ module ActiveSupport
@@at_exit = false
def pending(description = "", &block)
+ if description.is_a?(Symbol)
+ is_pending = $tags[description]
+ return block.call unless is_pending
+ end
+
if block_given?
failed = false
diff --git a/activesupport/lib/active_support/time.rb b/activesupport/lib/active_support/time.rb
new file mode 100644
index 0000000000..d36a683601
--- /dev/null
+++ b/activesupport/lib/active_support/time.rb
@@ -0,0 +1,14 @@
+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'
+ autoload :TimeWithZone, 'active_support/time_with_zone'
+ autoload :TimeZone, 'active_support/values/time_zone'
+
+ on_load_all do
+ [Duration, TimeWithZone, TimeZone]
+ end
+end
diff --git a/activesupport/lib/active_support/core/time/autoload.rb b/activesupport/lib/active_support/time/autoload.rb
index c9a7731b39..c9a7731b39 100644
--- a/activesupport/lib/active_support/core/time/autoload.rb
+++ b/activesupport/lib/active_support/time/autoload.rb