Last active
          April 7, 2021 20:58 
        
      - 
      
- 
        Save aflansburg/4d66ef3fee3995967d397e38e0c6054f to your computer and use it in GitHub Desktop. 
    Ruby Modules, require, module_function, and Rails
  
        
  
    
      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
    
  
  
    
  | # imagine this lives at app/lib/complicated_data | |
| module ComplicatedData | |
| def generate_complicated_plot_data(start_date: 30.days.ago, end_date: Date.today, type: nil) | |
| # implementation | |
| end | |
| # module_function ensures the method cannot be overridden or extended | |
| module_function :generate_complicated_plot_data | |
| 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
    
  
  
    
  | require 'complicated_data/plot' | |
| class SomeDataPlotController < SomeParentController | |
| # non-resourceful action that returns JSON | |
| def get_some_complicated_plot_data | |
| data = ComplicatedData.generate_complicated_plot_data | |
| render json: data | |
| end | |
| def index | |
| end | |
| def show | |
| end | |
| end | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment