Last active
August 29, 2015 14:02
-
-
Save andrzejkrzywda/063f2cb42e9142ff6e19 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
# CUSTOM EXCEPTIONS | |
class CallAlreadyInProgress < StandardError | |
end | |
class Dialer | |
def call(number) | |
raise CallAlreadyInProgress.new if call_already_in_progress? | |
end | |
end | |
dialer = Dialer.new | |
begin | |
dialer.call(number) | |
rescue CallAlreadyInProgress | |
ui_notifier.send_message("Call already in progress") | |
end | |
# with domain events | |
class CallAlreadyInProgress < Event | |
end | |
class ConnectionEstablished < Event | |
end | |
class Dialer | |
def call(number) | |
if call_already_in_progress? | |
CallAlreadyInProgress.new.publish() | |
return | |
end | |
ConnectionEstablished.new.publish() | |
end | |
end | |
# those two can be in different places of our project | |
event_bus.register(CallAlreadyInProgress, ui_notifier.send_message("Call already in progress")) | |
dialer.call(number) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment