Skip to content

Instantly share code, notes, and snippets.

@dirk
Created January 22, 2010 22:06
Show Gist options
  • Save dirk/284188 to your computer and use it in GitHub Desktop.
Save dirk/284188 to your computer and use it in GitHub Desktop.
class Project
include MongoMapper::Document
key :name, String, :required => true
key :description, String, :default => ''
key :status, Symbol, :required => true, :default => :open
key :client_id, ObjectId, :required => true
belongs_to :client
many :tasks, :dependent => :destroy
validates_inclusion_of :status, :within => [:open, :closed]
def moments
moments = []
self.tasks.each do |task|
moments.push *task.moments
end
return moments.sort {|a, b| b.date <=> a.date }
end
def incomplete_tasks
num = 0
self.tasks.each do |task|
if task.status != :complete
num += 1
end
end
return num
end
class << self
def attr_accessible
[:name, :description]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment