Replace alias method chaining with Module#alias_method_chain. [Marcel Molina Jr.]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4312 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Marcel Molina 2006-04-29 20:20:22 +00:00
parent 995167ec2e
commit 9f92dd3984
25 changed files with 52 additions and 96 deletions

@ -1,5 +1,7 @@
*SVN* *SVN*
* Replace alias method chaining with Module#alias_method_chain. [Marcel Molina Jr.]
* Replace Ruby's deprecated append_features in favor of included. [Marcel Molina Jr.] * Replace Ruby's deprecated append_features in favor of included. [Marcel Molina Jr.]
* Correct spurious documentation example code which results in a SyntaxError. [Marcel Molina Jr.] * Correct spurious documentation example code which results in a SyntaxError. [Marcel Molina Jr.]

@ -11,14 +11,12 @@ def self.included(base) #:nodoc:
base.class_eval do base.class_eval do
# Wrap inherited to create a new master helper module for subclasses. # Wrap inherited to create a new master helper module for subclasses.
class << self class << self
alias_method :inherited_without_helper, :inherited alias_method_chain :inherited, :helper
alias_method :inherited, :inherited_with_helper
end end
# Wrap initialize_template_class to extend new template class # Wrap initialize_template_class to extend new template class
# instances with the master helper module. # instances with the master helper module.
alias_method :initialize_template_class_without_helper, :initialize_template_class alias_method_chain :initialize_template_class, :helper
alias_method :initialize_template_class, :initialize_template_class_with_helper
end end
end end

@ -1,5 +1,7 @@
*SVN* *SVN*
* Replace alias method chaining with Module#alias_method_chain. [Marcel Molina Jr.]
* Replace Ruby's deprecated append_features in favor of included. [Marcel Molina Jr.] * Replace Ruby's deprecated append_features in favor of included. [Marcel Molina Jr.]
* Use #flush between switching from #write to #syswrite. Closes #4907. [Blair Zajac <blair@orcaware.com>] * Use #flush between switching from #write to #syswrite. Closes #4907. [Blair Zajac <blair@orcaware.com>]

@ -8,11 +8,8 @@ def self.included(base)
base.extend(ClassMethods) base.extend(ClassMethods)
base.class_eval do base.class_eval do
alias_method :perform_action_without_benchmark, :perform_action alias_method_chain :perform_action, :benchmark
alias_method :perform_action, :perform_action_with_benchmark alias_method_chain :render, :benchmark
alias_method :render_without_benchmark, :render
alias_method :render, :render_with_benchmark
end end
end end

@ -50,14 +50,9 @@ def render_component(options)
base.send :attr_accessor, :parent_controller base.send :attr_accessor, :parent_controller
base.class_eval do base.class_eval do
alias_method :process_cleanup_without_components, :process_cleanup alias_method_chain :process_cleanup, :components
alias_method :process_cleanup, :process_cleanup_with_components alias_method_chain :set_session_options, :components
alias_method_chain :flash, :components
alias_method :set_session_options_without_components, :set_session_options
alias_method :set_session_options, :set_session_options_with_components
alias_method :flash_without_components, :flash
alias_method :flash, :flash_with_components
alias_method :component_request?, :parent_controller alias_method :component_request?, :parent_controller
end end

@ -350,14 +350,9 @@ def remove_contradicting_conditions!(filters, conditions)
module InstanceMethods # :nodoc: module InstanceMethods # :nodoc:
def self.included(base) def self.included(base)
base.class_eval do base.class_eval do
alias_method :perform_action_without_filters, :perform_action alias_method_chain :perform_action, :filters
alias_method :perform_action, :perform_action_with_filters alias_method_chain :process, :filters
alias_method_chain :process_cleanup, :filters
alias_method :process_without_filters, :process
alias_method :process, :process_with_filters
alias_method :process_cleanup_without_filters, :process_cleanup
alias_method :process_cleanup, :process_cleanup_with_filters
end end
end end

@ -28,11 +28,8 @@ def self.included(base)
base.send :include, InstanceMethods base.send :include, InstanceMethods
base.class_eval do base.class_eval do
alias_method :assign_shortcuts_without_flash, :assign_shortcuts alias_method_chain :assign_shortcuts, :flash
alias_method :assign_shortcuts, :assign_shortcuts_with_flash alias_method_chain :process_cleanup, :flash
alias_method :process_cleanup_without_flash, :process_cleanup
alias_method :process_cleanup, :process_cleanup_with_flash
end end
end end

@ -12,8 +12,7 @@ def self.included(base)
base.class_eval do base.class_eval do
# Wrap inherited to create a new master helper module for subclasses. # Wrap inherited to create a new master helper module for subclasses.
class << self class << self
alias_method :inherited_without_helper, :inherited alias_method_chain :inherited, :helper
alias_method :inherited, :inherited_with_helper
end end
end end
end end

@ -317,9 +317,8 @@ module ControllerCapture #:nodoc:
def self.included(base) def self.included(base)
base.extend(ClassMethods) base.extend(ClassMethods)
base.class_eval do base.class_eval do
class <<self class << self
alias_method :new_without_capture, :new alias_method_chain :new, :capture
alias_method :new, :new_with_capture
end end
end end
end end

@ -3,12 +3,13 @@ module Layout #:nodoc:
def self.included(base) def self.included(base)
base.extend(ClassMethods) base.extend(ClassMethods)
base.class_eval do base.class_eval do
# NOTE: Can't use alias_method_chain here because +render_without_layout+ is already
# defined as a publicly exposed method
alias_method :render_with_no_layout, :render alias_method :render_with_no_layout, :render
alias_method :render, :render_with_a_layout alias_method :render, :render_with_a_layout
class << self class << self
alias_method :inherited_without_layout, :inherited alias_method_chain :inherited, :layout
alias_method :inherited, :inherited_with_layout
end end
end end
end end

@ -9,8 +9,7 @@ module Rescue
def self.included(base) #:nodoc: def self.included(base) #:nodoc:
base.extend(ClassMethods) base.extend(ClassMethods)
base.class_eval do base.class_eval do
alias_method :perform_action_without_rescue, :perform_action alias_method_chain :perform_action, :rescue
alias_method :perform_action, :perform_action_with_rescue
end end
end end

@ -8,12 +8,9 @@ module ActionController #:nodoc:
module SessionManagement #:nodoc: module SessionManagement #:nodoc:
def self.included(base) def self.included(base)
base.extend(ClassMethods) base.extend(ClassMethods)
base.send :alias_method, :process_without_session_management_support, :process base.send :alias_method_chain, :process, :session_management_support
base.send :alias_method, :process, :process_with_session_management_support base.send :alias_method_chain, :process_cleanup, :session_management_support
base.send :alias_method, :process_cleanup_without_session_management_support, :process_cleanup
base.send :alias_method, :process_cleanup, :process_cleanup_with_session_management_support
end end
module ClassMethods module ClassMethods

@ -18,8 +18,7 @@ def process_with_test(*args)
end end
end end
alias_method :process_without_test, :process alias_method_chain :process, :test
alias_method :process, :process_with_test
end end
class TestRequest < AbstractRequest #:nodoc: class TestRequest < AbstractRequest #:nodoc:

@ -1,5 +1,7 @@
*SVN* *SVN*
* Replace alias method chaining with Module#alias_method_chain. [Marcel Molina Jr.]
* Replace Ruby's deprecated append_features in favor of included. [Marcel Molina Jr.] * Replace Ruby's deprecated append_features in favor of included. [Marcel Molina Jr.]
* Fix test database name typo. [Marcel Molina Jr.] * Fix test database name typo. [Marcel Molina Jr.]

@ -4,10 +4,8 @@ module ActionController # :nodoc:
def self.included(base) # :nodoc: def self.included(base) # :nodoc:
class << base class << base
include ClassMethods include ClassMethods
alias_method :inherited_without_api, :inherited alias_method_chain :inherited, :api
alias_method :inherited, :inherited_with_api alias_method_chain :web_service_api, :require
alias_method :web_service_api_without_require, :web_service_api
alias_method :web_service_api, :web_service_api_with_require
end end
end end

@ -7,8 +7,7 @@ module ActionController # :nodoc:
def self.included(base) # :nodoc: def self.included(base) # :nodoc:
class << base class << base
include ClassMethods include ClassMethods
alias_method :inherited_without_action_controller, :inherited alias_method_chain :inherited, :action_controller
alias_method :inherited, :inherited_with_action_controller
end end
base.class_eval do base.class_eval do
alias_method :web_service_direct_invoke_without_controller, :web_service_direct_invoke alias_method :web_service_direct_invoke_without_controller, :web_service_direct_invoke

@ -126,8 +126,7 @@ def condition_hash(interceptors, *methods)
module InstanceMethods # :nodoc: module InstanceMethods # :nodoc:
def self.included(base) def self.included(base)
base.class_eval do base.class_eval do
alias_method :perform_invocation_without_interception, :perform_invocation alias_method_chain :perform_invocation, :interception
alias_method :perform_invocation, :perform_invocation_with_interception
end end
end end

@ -1,5 +1,7 @@
*SVN* *SVN*
* Replace alias method chaining with Module#alias_method_chain. [Marcel Molina Jr.]
* Replace Ruby's deprecated append_features in favor of included. [Marcel Molina Jr.] * Replace Ruby's deprecated append_features in favor of included. [Marcel Molina Jr.]
* Remove duplicate fixture entry in comments.yml. Closes #4923. [Blair Zajac <blair@orcaware.com>] * Remove duplicate fixture entry in comments.yml. Closes #4923. [Blair Zajac <blair@orcaware.com>]

@ -175,27 +175,12 @@ def self.included(base) #:nodoc:
base.class_eval do base.class_eval do
class << self class << self
include Observable include Observable
alias_method :instantiate_without_callbacks, :instantiate alias_method_chain :instantiate, :callbacks
alias_method :instantiate, :instantiate_with_callbacks
end end
alias_method :initialize_without_callbacks, :initialize [:initialize, :create_or_update, :valid?, :create, :update, :destroy].each do |method|
alias_method :initialize, :initialize_with_callbacks alias_method_chain method, :callbacks
end
alias_method :create_or_update_without_callbacks, :create_or_update
alias_method :create_or_update, :create_or_update_with_callbacks
alias_method :valid_without_callbacks, :valid?
alias_method :valid?, :valid_with_callbacks
alias_method :create_without_callbacks, :create
alias_method :create, :create_with_callbacks
alias_method :update_without_callbacks, :update
alias_method :update, :update_with_callbacks
alias_method :destroy_without_callbacks, :destroy
alias_method :destroy, :destroy_with_callbacks
end end
CALLBACKS.each do |method| CALLBACKS.each do |method|

@ -23,8 +23,7 @@ module ActiveRecord
module Locking module Locking
def self.included(base) #:nodoc: def self.included(base) #:nodoc:
base.class_eval do base.class_eval do
alias_method :update_without_lock, :update alias_method_chain :update, :lock
alias_method :update, :update_with_lock
end end
end end

@ -8,11 +8,9 @@ module ActiveRecord
module Timestamp module Timestamp
def self.included(base) # :nodoc: def self.included(base) # :nodoc:
base.class_eval do base.class_eval do
alias_method :create_without_timestamps, :create [:create, :update].each do |method|
alias_method :create, :create_with_timestamps alias_method_chain method, :timestamps
end
alias_method :update_without_timestamps, :update
alias_method :update, :update_with_timestamps
end end
end end

@ -13,11 +13,9 @@ def self.included(base)
base.extend(ClassMethods) base.extend(ClassMethods)
base.class_eval do base.class_eval do
alias_method :destroy_without_transactions, :destroy [:destroy, :save].each do |method|
alias_method :destroy, :destroy_with_transactions alias_method_chain method, :transactions
end
alias_method :save_without_transactions, :save
alias_method :save, :save_with_transactions
end end
end end

@ -217,14 +217,9 @@ module Validations
def self.included(base) # :nodoc: def self.included(base) # :nodoc:
base.extend ClassMethods base.extend ClassMethods
base.class_eval do base.class_eval do
alias_method :save_without_validation, :save alias_method_chain :save, :validation
alias_method :save, :save_with_validation alias_method_chain :save!, :validation!
alias_method_chain :update_attribute, :validation_skipping
alias_method :save_without_validation!, :save!
alias_method :save!, :save_with_validation!
alias_method :update_attribute_without_validation_skipping, :update_attribute
alias_method :update_attribute, :update_attribute_with_validation_skipping
end end
end end

@ -1,5 +1,7 @@
*SVN* *SVN*
* Replace alias method chaining with Module#alias_method_chain. [Marcel Molina Jr.]
* Strip out punctuation on predicates or bang methods being aliased with alias_method_chain since target?_without_feature is not a valid method name. Add tests for Module#alias_method_chain. [Marcel Molina Jr.] * Strip out punctuation on predicates or bang methods being aliased with alias_method_chain since target?_without_feature is not a valid method name. Add tests for Module#alias_method_chain. [Marcel Molina Jr.]
* Replace Ruby's deprecated append_features in favor of included. [Marcel Molina Jr.] * Replace Ruby's deprecated append_features in favor of included. [Marcel Molina Jr.]

@ -3,8 +3,7 @@ module CoreExtensions #:nodoc:
module Time #:nodoc: module Time #:nodoc:
# Enables the use of time calculations within Time itself # Enables the use of time calculations within Time itself
module Calculations module Calculations
def self.append_features(base) #:nodoc: def self.included(base) #:nodoc:
super
base.extend(ClassMethods) base.extend(ClassMethods)
end end