Skip to content

Instantly share code, notes, and snippets.

@dkubb
Forked from ravinggenius/ScratchPad.rb
Created January 11, 2009 07:51
Show Gist options
  • Save dkubb/45667 to your computer and use it in GitHub Desktop.
Save dkubb/45667 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
module Part
def self.included(model)
model.class_eval <<-RUBY, __FILE__, __LINE__ + 1
include DataMapper::Resource
property :id, Serial
property :subtitle, String, :nullable => false
belongs_to :node
is :list
RUBY
end
end
class PartText
include Part
property :data, Text, :nullable => false
end
class PartTable
include Part
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