Created
June 12, 2009 18:15
-
-
Save andrewsardone/128808 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Cookie cutter code from ActiveRecord::Callbacks | |
# Adds before_move and after_move callbacks for the awesome_nested_set | |
# plugin by Collective Idea | |
# http://github.com/collectiveidea/awesome_nested_set/tree/master | |
# | |
# RAILS_ROOT/vendor/plugins/awesome_nested_set_extensions/lib/callbacks.rb | |
module CollectiveIdea #:nodoc: | |
module Acts #:nodoc: | |
module NestedSet #:nodoc: | |
module Callbacks | |
CALLBACKS = %w(before_move after_move) | |
def self.included(base) #:nodoc: | |
base.extend Observable | |
base.send :alias_method_chain, :move_to, :callbacks | |
base.send :include, ActiveSupport::Callbacks | |
base.define_callbacks *CALLBACKS | |
end | |
# Is called _before_ <tt>base.move_to</tt> | |
def before_move() end | |
# Is called _after_ <tt>base.move_to</tt> | |
def after_move() end | |
def move_to_with_callbacks #:nodoc: | |
return false if callback(:before_save) == false | |
if result = move_to_without_callbacks | |
callback(:after_move) | |
end | |
result | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment