Skip to content

Instantly share code, notes, and snippets.

@alx
Created October 19, 2009 16:12
Show Gist options
  • Save alx/213486 to your computer and use it in GitHub Desktop.
Save alx/213486 to your computer and use it in GitHub Desktop.
class User
include DataMapper::Resource
property :id, Serial
property :name, String
property :created_at, DateTime
has n, :tags
end
class Tag
include DataMapper::Resource
property :id, Serial
property :created_at, DateTime
property :updated_at, DateTime
property :credits, Integer, :default => 0
belongs_to :user
has n, :products
def has_credit?
remaining_credit > 0
end
def remaining_credit
self.credits - products_value
end
def products_value
value = 0
self.products.each do |product|
value += product.value
end
return value
end
end
class Product
include DataMapper::Resource
property :id, Serial
property :name, String
property :created_at, DateTime
property :value, Integer, :default=>1
validates_present :name
belongs_to :user
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment