Skip to content

Instantly share code, notes, and snippets.

@ihumanable
Created November 23, 2021 00:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ihumanable/e92ad12bfeb71788a5c2a7bcc7e294cd to your computer and use it in GitHub Desktop.
Save ihumanable/e92ad12bfeb71788a5c2a7bcc7e294cd to your computer and use it in GitHub Desktop.
Patch Call Graph
assert {:bad, :error} == Discord.send_message(%Message{})
# We start at the Facade
Discord.send_message(%Message{}) {
# The Facade calls the Delegate
Delegate.send_message(message) {
# The Delegate checks if the Server has a patch for send_message/1
Server.delegate(Discord, :send_message, [message]) {
# The Server doesn't, so it calls the Original
Original.send_message(message) {
# The Original calls the Delegate's validate_message/1 function
Delegate.validate_message(message) {
# The Delegate checks if the Server has a patch for validate_message/1
Server.delegate(Discord, :validate_message, [message]) {
# The Server does have a patch for validate_message/1 so it returns it
} -> {:bad, :error}
# The Delegate returns the patched value to the Original
} -> {:bad, :error}
# The Original's with statement fails to match, so it returns the value
} -> {:bad, :error}
# The Server returns the Original's result
} -> {:bad, :error}
# The Delegate returns the Server's result
} -> {:bad, :error}
# The Facade returns the Delete's result
} -> {:bad, :error}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment