Permalink
Browse files

Assigned :terminator => 'result == true' for the persist callback cha…

…in to make it compatible with rails 3
  • Loading branch information...
1 parent 830170c commit 9280227b0983fec711d87b55b3cd7d33bf8114e5 Marc-Andre Gagnon committed Jun 18, 2010
Showing with 10 additions and 13 deletions.
  1. +10 −13 lib/authlogic/session/callbacks.rb
@@ -15,7 +15,7 @@ module Session
# persist
# after_persisting
# [save record if record.changed?]
- #
+ #
# before_validation
# before_validation_on_create
# before_validation_on_update
@@ -24,15 +24,15 @@ module Session
# after_validation_on_create
# after_validation
# [save record if record.changed?]
- #
+ #
# before_save
# before_create
# before_update
# after_update
# after_create
# after_save
# [save record if record.changed?]
- #
+ #
# before_destroy
# [save record if record.changed?]
# destroy
@@ -60,13 +60,14 @@ module Callbacks
"before_save", "before_create", "before_update", "after_update", "after_create", "after_save",
"before_destroy", "after_destroy"
]
-
+
def self.included(base) #:nodoc:
base.send :include, ActiveSupport::Callbacks
base.define_callbacks *METHODS
-
+ base.define_callbacks 'persist', :terminator => 'result == true'
+
# If Rails 3, support the new callback syntax
- if base.send(base.respond_to?(:singleton_class) ? :singleton_class : :metaclass).method_defined?(:set_callback)
+ if base.singleton_class.method_defined?(:set_callback)
METHODS.each do |method|
base.class_eval <<-"end_eval", __FILE__, __LINE__
def self.#{method}(*methods, &block)
@@ -76,20 +77,16 @@ def self.#{method}(*methods, &block)
end
end
end
-
+
private
METHODS.each do |method|
class_eval <<-"end_eval", __FILE__, __LINE__
def #{method}
- run_callbacks(:#{method}) { |result, object| result == false }
+ run_callbacks(:#{method})
end
end_eval
end
-
- def persist
- run_callbacks(:persist) { |result, object| result == true }
- end
-
+
def save_record(alternate_record = nil)
r = alternate_record || record
r.save_without_session_maintenance(:validate => false) if r && r.changed? && !r.readonly?

0 comments on commit 9280227

Please sign in to comment.