Skip to content

Commit

Permalink
Callbacks, DeprecatedCallbacks = NewCallbacks, Callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Oct 13, 2009
1 parent 9bc8def commit 21e7b84
Show file tree
Hide file tree
Showing 15 changed files with 1,263 additions and 1,457 deletions.
8 changes: 3 additions & 5 deletions actionpack/lib/abstract_controller/callbacks.rb
@@ -1,13 +1,11 @@
require "active_support/new_callbacks"

module AbstractController
module Callbacks
extend ActiveSupport::Concern

# Uses ActiveSupport::NewCallbacks as the base functionality. For
# Uses ActiveSupport::Callbacks as the base functionality. For
# more details on the whole callback system, read the documentation
# for ActiveSupport::NewCallbacks.
include ActiveSupport::NewCallbacks
# for ActiveSupport::Callbacks.
include ActiveSupport::Callbacks

included do
define_callbacks :process_action, :terminator => "response_body"
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_dispatch/middleware/callbacks.rb
@@ -1,6 +1,6 @@
module ActionDispatch
class Callbacks
include ActiveSupport::NewCallbacks
include ActiveSupport::Callbacks

define_callbacks :call, :terminator => "result == false", :rescuable => true
define_callbacks :prepare, :scope => :name
Expand Down
10 changes: 4 additions & 6 deletions activemodel/lib/active_model/validations.rb
@@ -1,12 +1,10 @@
require 'active_support/core_ext/array/extract_options'
require 'active_support/core_ext/hash/keys'
require 'active_support/concern'
require 'active_support/callbacks'

module ActiveModel
module Validations
extend ActiveSupport::Concern
include ActiveSupport::NewCallbacks
include ActiveSupport::Callbacks

included do
define_callbacks :validate, :scope => :name
Expand Down Expand Up @@ -99,7 +97,7 @@ def valid?
def invalid?
!valid?
end

protected
# Hook method defining how an attribute value should be retieved. By default this is assumed
# to be an instance named after the attribute. Override this method in subclasses should you
Expand All @@ -110,9 +108,9 @@ def invalid?
# def initialize(data = {})
# @data = data
# end
#
#
# private
#
#
# def read_attribute_for_validation(key)
# @data[key]
# end
Expand Down
Expand Up @@ -476,7 +476,7 @@ def remove_records(*records)

def callback(method, record)
callbacks_for(method).each do |callback|
ActiveSupport::Callbacks::Callback.new(method, callback, record).call(@owner, record)
ActiveSupport::DeprecatedCallbacks::Callback.new(method, callback, record).call(@owner, record)
end
end

Expand Down
4 changes: 2 additions & 2 deletions activerecord/lib/active_record/callbacks.rb
Expand Up @@ -20,7 +20,7 @@ module ActiveRecord
# * (6) <tt>after_save</tt>
#
# That's a total of eight callbacks, which gives you immense power to react and prepare for each state in the
# Active Record lifecycle. The sequence for calling <tt>Base#save</tt> for an existing record is similar, except that each
# Active Record lifecycle. The sequence for calling <tt>Base#save</tt> for an existing record is similar, except that each
# <tt>_on_create</tt> callback is replaced by the corresponding <tt>_on_update</tt> callback.
#
# Examples:
Expand Down Expand Up @@ -210,7 +210,7 @@ module ActiveRecord
# instead of quietly returning +false+.
module Callbacks
extend ActiveSupport::Concern
include ActiveSupport::NewCallbacks
include ActiveSupport::Callbacks

CALLBACKS = [
:after_initialize, :after_find, :before_validation, :after_validation,
Expand Down
Expand Up @@ -32,7 +32,7 @@ module ConnectionAdapters # :nodoc:
class AbstractAdapter
include Quoting, DatabaseStatements, SchemaStatements
include QueryCache
include ActiveSupport::Callbacks
include ActiveSupport::DeprecatedCallbacks
define_callbacks :checkout, :checkin

@@row_even = true
Expand Down Expand Up @@ -75,7 +75,7 @@ def supports_count_distinct?
def supports_ddl_transactions?
false
end

# Does this adapter support savepoints? PostgreSQL and MySQL do, SQLite
# does not.
def supports_savepoints?
Expand Down
14 changes: 7 additions & 7 deletions activerecord/lib/active_record/validations.rb
Expand Up @@ -59,15 +59,15 @@ def full_messages(options = {})
end

# Translates an error message in it's default scope (<tt>activerecord.errrors.messages</tt>).
# Error messages are first looked up in <tt>models.MODEL.attributes.ATTRIBUTE.MESSAGE</tt>, if it's not there,
# it's looked up in <tt>models.MODEL.MESSAGE</tt> and if that is not there it returns the translation of the
# default message (e.g. <tt>activerecord.errors.messages.MESSAGE</tt>). The translated model name,
# Error messages are first looked up in <tt>models.MODEL.attributes.ATTRIBUTE.MESSAGE</tt>, if it's not there,
# it's looked up in <tt>models.MODEL.MESSAGE</tt> and if that is not there it returns the translation of the
# default message (e.g. <tt>activerecord.errors.messages.MESSAGE</tt>). The translated model name,
# translated attribute name and the value are available for interpolation.
#
# When using inheritance in your models, it will check all the inherited models too, but only if the model itself
# hasn't been found. Say you have <tt>class Admin < User; end</tt> and you wanted the translation for the <tt>:blank</tt>
# error +message+ for the <tt>title</tt> +attribute+, it looks for these translations:
#
#
# <ol>
# <li><tt>activerecord.errors.models.admin.attributes.title.blank</tt></li>
# <li><tt>activerecord.errors.models.admin.blank</tt></li>
Expand All @@ -80,10 +80,10 @@ def generate_message(attribute, message = :invalid, options = {})
message, options[:default] = options[:default], message if options[:default].is_a?(Symbol)

defaults = @base.class.self_and_descendants_from_active_record.map do |klass|
[ :"models.#{klass.name.underscore}.attributes.#{attribute}.#{message}",
[ :"models.#{klass.name.underscore}.attributes.#{attribute}.#{message}",
:"models.#{klass.name.underscore}.#{message}" ]
end

defaults << options.delete(:default)
defaults = defaults.compact.flatten << :"messages.#{message}"

Expand All @@ -104,7 +104,7 @@ def generate_message(attribute, message = :invalid, options = {})
module Validations
extend ActiveSupport::Concern

include ActiveSupport::Callbacks
include ActiveSupport::DeprecatedCallbacks
include ActiveModel::Validations

included do
Expand Down
2 changes: 1 addition & 1 deletion activesupport/lib/active_support/autoload.rb
Expand Up @@ -8,14 +8,14 @@ module ActiveSupport
autoload :Concern, 'active_support/concern'
autoload :ConcurrentHash, 'active_support/concurrent_hash'
autoload :DependencyModule, 'active_support/dependency_module'
autoload :DeprecatedCallbacks, 'active_support/deprecated_callbacks'
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 :NewCallbacks, 'active_support/new_callbacks'
autoload :OptionMerger, 'active_support/option_merger'
autoload :Orchestra, 'active_support/orchestra'
autoload :OrderedHash, 'active_support/ordered_hash'
Expand Down

0 comments on commit 21e7b84

Please sign in to comment.