Created
April 26, 2012 12:54
-
-
Save pechorin/2499364 to your computer and use it in GitHub Desktop.
state miaso
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
class A | |
state_machine do | |
state :active | |
state :removed | |
event :remove do | |
transition :active => :removed | |
end | |
after_transition :active => :removed, :do => :fire_callbacks | |
end | |
def nested_records | |
B.all | |
end | |
def fire_callbacks | |
send_to_external_server | |
nested_record.skip_callback_after_remove = true | |
nested_record.remove | |
end | |
end | |
class B | |
attr_accessor :skip_callback_after_remove | |
state_machine do | |
state :active | |
state :removed | |
event :remove | |
transition :active => :removed | |
end | |
# если у b есть a и a -> removed -> то только тогда вызываем коллбек | |
after_transition :active => :removed, :do => :fire_callbacks | |
end | |
def fire_callbacks | |
unless skip_callbacks_after_remove | |
send_to_external_server | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment