Skip to content

Instantly share code, notes, and snippets.

@avand
Created November 23, 2009 17:40
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 avand/241220 to your computer and use it in GitHub Desktop.
Save avand/241220 to your computer and use it in GitHub Desktop.
# Given a set of class names, will require objects of those types to have been populated
# Usage: depends_on(User, Post, Comment)
def depends_on(*args)
raise "Depends on #{args.map{ |a| a.name.pluralize }.to_sentence.downcase} to populate data." if args.any? { |a| a.count.zero? }
args.each { |a| eval "@#{a.name.underscore.pluralize} = #{a}.all" }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment