Skip to content

Instantly share code, notes, and snippets.

@pechorin
Created April 26, 2012 12:54
Show Gist options
  • Save pechorin/2499364 to your computer and use it in GitHub Desktop.
Save pechorin/2499364 to your computer and use it in GitHub Desktop.
state miaso
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