Skip to content

Instantly share code, notes, and snippets.

@krisleech
Created April 6, 2013 17:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krisleech/5326823 to your computer and use it in GitHub Desktop.
Save krisleech/5326823 to your computer and use it in GitHub Desktop.
Decoupled Analytics
class SomeBusinessCase
include Wisper
def execute(attributes)
if true
publish(:some_business_case_successful, details)
else
publish(:some_business_case_failed, details)
end
end
end
# app/listeners/statistics_listener.rb
class StatisticsListener
def some_business_case_successful(details)
# store stats...
end
# lots more callback methods...
end
class SomeController
def create
business_case = SomeBusinessCase.new
business_case.subscribe(StatisticsListener.new)
business_case.on(:some_business_case_successful) { |details| redirect_to somewhere }
business_case.on(:some_business_case_failed) { |details| render :action => :new }
business_case.execute(params[:stuff]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment