aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/autoload.rb3
-rw-r--r--activesupport/lib/active_support/cache/strategy/local_cache.rb2
-rw-r--r--activesupport/lib/active_support/concern.rb25
-rw-r--r--activesupport/lib/active_support/dependency_module.rb12
-rw-r--r--activesupport/lib/active_support/new_callbacks.rb30
5 files changed, 54 insertions, 18 deletions
diff --git a/activesupport/lib/active_support/autoload.rb b/activesupport/lib/active_support/autoload.rb
index ed229d1c5f..75706855d6 100644
--- a/activesupport/lib/active_support/autoload.rb
+++ b/activesupport/lib/active_support/autoload.rb
@@ -5,7 +5,7 @@ module ActiveSupport
autoload :BufferedLogger, 'active_support/buffered_logger'
autoload :Cache, 'active_support/cache'
autoload :Callbacks, 'active_support/callbacks'
- autoload :NewCallbacks, 'active_support/new_callbacks'
+ autoload :Concern, 'active_support/concern'
autoload :ConcurrentHash, 'active_support/concurrent_hash'
autoload :DependencyModule, 'active_support/dependency_module'
autoload :Deprecation, 'active_support/deprecation'
@@ -15,6 +15,7 @@ module ActiveSupport
autoload :MessageEncryptor, 'active_support/message_encryptor'
autoload :MessageVerifier, 'active_support/message_verifier'
autoload :Multibyte, 'active_support/multibyte'
+ autoload :NewCallbacks, 'active_support/new_callbacks'
autoload :OptionMerger, 'active_support/option_merger'
autoload :OrderedHash, 'active_support/ordered_hash'
autoload :OrderedOptions, 'active_support/ordered_options'
diff --git a/activesupport/lib/active_support/cache/strategy/local_cache.rb b/activesupport/lib/active_support/cache/strategy/local_cache.rb
index 4bbcd8e4c4..3b5fccc737 100644
--- a/activesupport/lib/active_support/cache/strategy/local_cache.rb
+++ b/activesupport/lib/active_support/cache/strategy/local_cache.rb
@@ -45,7 +45,7 @@ module ActiveSupport
elsif value.nil?
value = super
local_cache.write(key, value || NULL) if local_cache
- value
+ value.duplicable? ? value.dup : value
else
# forcing the value to be immutable
value.duplicable? ? value.dup : value
diff --git a/activesupport/lib/active_support/concern.rb b/activesupport/lib/active_support/concern.rb
new file mode 100644
index 0000000000..dcf1e8152f
--- /dev/null
+++ b/activesupport/lib/active_support/concern.rb
@@ -0,0 +1,25 @@
+require 'active_support/dependency_module'
+
+module ActiveSupport
+ module Concern
+ include DependencyModule
+
+ def append_features(base)
+ if super
+ base.extend const_get("ClassMethods") if const_defined?("ClassMethods")
+ base.send :include, const_get("InstanceMethods") if const_defined?("InstanceMethods")
+ base.class_eval(&@_included_block) if instance_variable_defined?("@_included_block")
+ end
+ end
+
+ def included(base = nil, &block)
+ if base.nil?
+ @_included_block = block
+ else
+ super
+ end
+ end
+
+ alias_method :include, :depends_on
+ end
+end
diff --git a/activesupport/lib/active_support/dependency_module.rb b/activesupport/lib/active_support/dependency_module.rb
index 9872b9654b..6847c0f86a 100644
--- a/activesupport/lib/active_support/dependency_module.rb
+++ b/activesupport/lib/active_support/dependency_module.rb
@@ -1,19 +1,9 @@
module ActiveSupport
module DependencyModule
def append_features(base)
- return if base < self
+ return false if base < self
(@_dependencies ||= []).each { |dep| base.send(:include, dep) }
super
- base.extend const_get("ClassMethods") if const_defined?("ClassMethods")
- base.class_eval(&@_included_block) if instance_variable_defined?("@_included_block")
- end
-
- def included(base = nil, &block)
- if base.nil?
- @_included_block = block
- else
- super
- end
end
def depends_on(*mods)
diff --git a/activesupport/lib/active_support/new_callbacks.rb b/activesupport/lib/active_support/new_callbacks.rb
index b6cbdbb6b0..58d4c47ccb 100644
--- a/activesupport/lib/active_support/new_callbacks.rb
+++ b/activesupport/lib/active_support/new_callbacks.rb
@@ -286,7 +286,14 @@ module ActiveSupport
filter
when Proc
@klass.send(:define_method, method_name, &filter)
- method_name << (filter.arity == 1 ? "(self)" : "")
+ method_name << case filter.arity
+ when 1
+ "(self)"
+ when 2
+ " self, Proc.new "
+ else
+ ""
+ end
when Method
@klass.send(:define_method, "#{method_name}_method") { filter }
@klass.class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
@@ -311,6 +318,11 @@ module ActiveSupport
def #{method_name}(&blk)
if :#{kind} == :around && #{method_name}_object.respond_to?(:filter)
#{method_name}_object.send("filter", self, &blk)
+ # TODO: Deprecate this
+ elsif #{method_name}_object.respond_to?(:before) && #{method_name}_object.respond_to?(:after)
+ should_continue = #{method_name}_object.before(self)
+ yield if should_continue
+ #{method_name}_object.after(self)
else
#{method_name}_object.send("#{kind}_#{name}", self, &blk)
end
@@ -319,7 +331,13 @@ module ActiveSupport
else
@klass.class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
def #{method_name}(&blk)
- #{method_name}_object.send("#{kind}_#{name}", self, &blk)
+ if #{method_name}_object.respond_to?(:#{kind})
+ #{method_name}_object.#{kind}(self, &blk)
+ elsif #{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
end
@@ -367,7 +385,7 @@ module ActiveSupport
# The _run_save_callbacks method can optionally take a key, which
# will be used to compile an optimized callback method for each
# key. See #define_callbacks for more information.
- def _define_runner(symbol, str, options)
+ def _define_runner(symbol, str, options)
str = <<-RUBY_EVAL
def _run_#{symbol}_callbacks(key = nil)
if key
@@ -464,7 +482,9 @@ module ActiveSupport
self._#{symbol}_callbacks.delete_if {|c| c.matches?(type, :#{symbol}, filter)}
Callback.new(filter, type, options.dup, self, :#{symbol})
end
- self._#{symbol}_callbacks.push(*filters)
+ options[:prepend] ?
+ self._#{symbol}_callbacks.unshift(*filters) :
+ self._#{symbol}_callbacks.push(*filters)
_define_runner(:#{symbol},
self._#{symbol}_callbacks.compile(nil, :terminator => _#{symbol}_terminator),
options)
@@ -479,7 +499,7 @@ module ActiveSupport
filter = self._#{symbol}_callbacks.find {|c| c.matches?(type, :#{symbol}, filter) }
per_key = options[:per_key] || {}
- if filter
+ if filter && options.any?
filter.recompile!(options, per_key)
else
self._#{symbol}_callbacks.delete(filter)