Skip to content

Instantly share code, notes, and snippets.

@aflansburg
Last active April 7, 2021 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aflansburg/4d66ef3fee3995967d397e38e0c6054f to your computer and use it in GitHub Desktop.
Save aflansburg/4d66ef3fee3995967d397e38e0c6054f to your computer and use it in GitHub Desktop.
Ruby Modules, require, module_function, and Rails
# 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
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