Skip to content

Instantly share code, notes, and snippets.

@ravinggenius
Created January 10, 2009 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ravinggenius/45488 to your computer and use it in GitHub Desktop.
Save ravinggenius/45488 to your computer and use it in GitHub Desktop.
include 'dm-is-list'
class Node
include DataMapper::Resource
property :id, Serial
# other properties...
has n, :parts
end
# Part is abstract, but should create a 'header' table
class Part
include DataMapper::Resource
property :id, Serial
# multi-table inheritence
# there should be fields for the derived class name and its id
#property :type, Discriminator # ??
property :subtitle, String, :nullable => false
belongs_to :node
is :list
end
class PartText < Part
include DataMapper::Resource
property :id, Serial
property :data, Text, :nullable => false
end
class PartTable < Part
include DataMapper::Resource
property :id, Serial
property :caption, String
property :cells, Csv, :nullable => false
# other properties
end
# Desired Usage
#
# table = PartTable.new
# table.caption = '...'
# table.cells = 'Some,csv'
#
# text = PartText.new
# text.data = 'Really long passage of text'
#
# node = Node.new
# node.parts << table
# node.parts << text
# node.save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment