Created
          April 6, 2013 17:06 
        
      - 
      
- 
        Save krisleech/5326823 to your computer and use it in GitHub Desktop. 
    Decoupled Analytics 
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | 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 | 
  
    
      This file contains hidden or 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
    
  
  
    
  | # app/listeners/statistics_listener.rb | |
| class StatisticsListener | |
| def some_business_case_successful(details) | |
| # store stats... | |
| end | |
| # lots more callback methods... | |
| end | 
  
    
      This file contains hidden or 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
    
  
  
    
  | 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