Be able to configure default callbacks
frostmark opened this issue · 0 comments
frostmark commented
Hi there!
I would like to suggest adding the ability for configuring default callbacks (for example, on_assignment
)
I see an interface something like this:
Vanity.configure do |config|
config.on_assignment = proc do |...params|
# does something useful
end
config.after_assignment = proc do |...params|
# does something useful
end
end
Also, we can redefine the default callback if we define that inside some test
vanity/lib/vanity/experiment/base.rb
Line 90 in 4e3b416
That will help define some logic once. In my case: I want to make pub/sub logic and broadcast events from after_assignment
callback:
class VanityEventPublisher
include Wisper::Publisher
def after_assignment(assignment)
broadcast(:after_assignment, assignment)
end
end
class AbTestEventListener
def after_assignment(assignment)
Analytics::Tracker.track!(:some_event)
end
end
Vanity.configure do |config|
config.after_assignment = proc do |assignment|
VanityEventPublisher.new.after_assignment(assignment)
end
end
Also, I think this would be helpful for some loggers and so on