Created
December 28, 2009 18:46
-
-
Save josevalim/264842 to your computer and use it in GitHub Desktop.
This file contains 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
# Instead of: | |
module MailForm::Callbacks | |
def self.extended(base) | |
base.class_eval do | |
include ActiveSupport::Callbacks | |
define_callbacks :create, :terminator => "result == false", :scope => [:kind, :name] | |
end | |
end | |
def before_create(*args, &block) | |
set_callback(:create, :before, *args, &block) | |
end | |
def around_create(*args, &block) | |
set_callback(:create, :around, *args, &block) | |
end | |
def after_create(*args, &block) | |
options = args.extract_options! | |
options[:prepend] = true | |
options[:if] = Array(options[:if]) << "!halted && value != false" | |
set_callback(:create, :after, *(args << options), &block) | |
end | |
end | |
class MailForm::Base | |
extend MailForm::Callbacks | |
end | |
# I would be able to just do: | |
class MailForm::Base | |
include ActiveModel::Callbacks | |
define_model_callbacks :create | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment