Skip to content

Commit

Permalink
Added compatibility layer for new ActiveSupport::Callback syntax to b…
Browse files Browse the repository at this point in the history
…e used in Rails 3.
  • Loading branch information
isomorphix authored and binarylogic committed Jan 14, 2010
1 parent f2e9517 commit 1480388
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/authlogic/acts_as_authentic/password.rb
Expand Up @@ -180,6 +180,17 @@ module Callbacks
def self.included(klass)
return if klass.crypted_password_field.nil?
klass.define_callbacks *METHODS

# If Rails 3, support the new callback syntax
if klass.metaclass.method_defined?(:set_callback)
METHODS.each do |method|
klass.class_eval <<-"end_eval", __FILE__, __LINE__
def self.#{method}(*methods, &block)
set_callback :#{method}, *methods, &block
end
end_eval
end
end
end

private
Expand Down
11 changes: 11 additions & 0 deletions lib/authlogic/session/callbacks.rb
Expand Up @@ -64,6 +64,17 @@ module Callbacks
def self.included(base) #:nodoc:
base.send :include, ActiveSupport::Callbacks
base.define_callbacks *METHODS

# If Rails 3, support the new callback syntax
if base.metaclass.method_defined?(:set_callback)
METHODS.each do |method|
base.class_eval <<-"end_eval", __FILE__, __LINE__
def self.#{method}(*methods, &block)
set_callback :#{method}, *methods, &block
end
end_eval
end
end
end

private
Expand Down

0 comments on commit 1480388

Please sign in to comment.