Skip to content

Instantly share code, notes, and snippets.

@george
Forked from unixmonkey/flying_spaghetti_monster.rb
Created November 11, 2010 18:45
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 george/672962 to your computer and use it in GitHub Desktop.
Save george/672962 to your computer and use it in GitHub Desktop.
# == Schema Information
#
# Table name: flying_spaghetti_monsters
#
# id :integer(4) not null, primary key
# awesomeness :string
# meatballs :boolean
# last_seen :datetime
# model-specific requires
require 'foo'
class FlyingSpaghettiMonster < ActiveRecord::Base
# includes & plugin declarations
include AwesomeSauce
acts_as_omnicient
# class variables & constants
@@per_page = 10
PANT_SIZES = %w(Small Medium Large Humongaginormous)
# accessors & readers
attr_accessible :awesomeness
# before/after/around filters
before_create :set_initial_awesomeness
# validations
validates_presence_of :meatballs
# relationships
has_one :all_seeing_eye
has_many :noodly_appendages
belongs_to :dimension
# named_scopes
named_scope :recently_spotted, lambda { :conditions => ['last_seen >=', 1.month.ago] }
# "self"-ish definitions (class methods)
def self.email_worshippers
emails = worshippers.all.collect(&:email)
WorshipperMailer.deliver_newsletter_to(emails)
end
# virtual attribute definitions
def genus
"flagamorphicus #{awesomeness}ica"
end
def supa_awesome?
true if awesome == 'supa'
end
# normal definitions (instance methods)
def appendage_count
appendages.all.count
end
def add_appendage
appendage.create!(:flying_spaghetti_monster_id => id, :size => 'monsterous')
end
# defined getters & setters
def per_page
@@per_page
end
def per_page=(num)
@@per_page = (num + 1)
end
# protected methods
protected
def worshipper_names
worshippers.all.collect(&:name)
end
# private methods
private
def set_initial_awesomeness
awesomeness = 'semi-awesome'
end
end
__END__
Unstructured heredoc text or template
Seriously, don't use this unless you
are doing some fancy single-file app
or something
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment