Created
October 23, 2013 05:20
-
-
Save moro/7112972 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
class Foo < ActiveRecord::Base | |
after_save :do_something, unless: :other_situation? | |
class << self | |
def other_situation | |
begin | |
Thread.current[:other_situation] = true | |
yield | |
ensure | |
Thread.current[:other_situation] = nil | |
end | |
end | |
end | |
def do_something | |
end | |
def other_situation? | |
Thread.current[:other_situation] | |
end | |
end | |
Foo.other_situation do | |
foo.save! | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment