Created
May 14, 2018 12:36
-
-
Save tdouce/4d899ab6e3d400f1f13b9e1785eb3397 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
# option #1 | |
# Granted, this would require that bugsnag be a dependency of the gem. And, that might | |
# not be an option. but, anyhoo | |
module Crex | |
# This could be a parent class that is configured in a similar way api_client gem does | |
class RescueStrategy | |
def self.call(e) | |
Bugsnag.notify(e) | |
end | |
end | |
class Experiment | |
def allocate | |
# do stuff | |
rescue => e | |
RescueStrategy.call(e) | |
end | |
end | |
end | |
Crex::Experiment.new.allocate | |
# option #2 | |
module Crex | |
class Experiment | |
def allocate(rescue_strategy: nil) | |
# do stuff | |
rescue => e | |
if rescue_strategy | |
rescue_strategy.notify(e) | |
end | |
end | |
end | |
end | |
# Provided by client | |
class MyCustomRescueStrategy | |
def self.notify(e) | |
Bugsnag.notify(e) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment