Module: Authlogic::Session::Callbacks
- Included in:
- Base
- Defined in:
- lib/authlogic/session/callbacks.rb
Overview
Callbacks
Just like in ActiveRecord you have before_save, before_validation, etc. You have similar callbacks with Authlogic, see all callbacks below.
Constant Summary collapse
- CALLBACKS =
%w(before_create after_create before_destroy after_destroy before_save after_save before_update after_update before_validation after_validation)
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#destroy_with_callbacks ⇒ Object
Run the following callbacks:.
-
#save_with_callbacks ⇒ Object
Runs the following callbacks:.
-
#validate_with_callbacks ⇒ Object
Runs the following callbacks:.
Class Method Details
.included(base) ⇒ Object
:nodoc:
9 10 11 12 13 14 15 16 |
# File 'lib/authlogic/session/callbacks.rb', line 9 def self.included(base) #:nodoc: [:destroy, :save, :validate].each do |method| base.send :alias_method_chain, method, :callbacks end base.send :include, ActiveSupport::Callbacks base.define_callbacks *CALLBACKS end |
Instance Method Details
#destroy_with_callbacks ⇒ Object
Run the following callbacks:
before_destroy
destroy
after_destroy # only if destroy is successful
23 24 25 26 27 28 |
# File 'lib/authlogic/session/callbacks.rb', line 23 def destroy_with_callbacks run_callbacks(:before_destroy) result = destroy_without_callbacks run_callbacks(:after_destroy) if result result end |
#save_with_callbacks ⇒ Object
Runs the following callbacks:
before_save
before_create # only if new_session? == true
before_update # only if new_session? == false
save
# the following are only run is save is successful
after_save
before_update # only if new_session? == false
before_create # only if new_session? == true
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/authlogic/session/callbacks.rb', line 40 def save_with_callbacks run_callbacks(:before_save) if new_session? run_callbacks(:before_create) else run_callbacks(:before_update) end result = save_without_callbacks if result run_callbacks(:after_save) if new_session? run_callbacks(:after_create) else run_callbacks(:after_update) end end result end |
#validate_with_callbacks ⇒ Object
Runs the following callbacks:
before_validation
validate
after_validation # only if errors.empty?
65 66 67 68 69 |
# File 'lib/authlogic/session/callbacks.rb', line 65 def validate_with_callbacks run_callbacks(:before_validation) validate_without_callbacks run_callbacks(:after_validation) if errors.empty? end |