Skip to content

Instantly share code, notes, and snippets.

@abevoelker
Created March 19, 2012 18:32
Show Gist options
  • Save abevoelker/2123152 to your computer and use it in GitHub Desktop.
Save abevoelker/2123152 to your computer and use it in GitHub Desktop.
concrete table inheritance
# app/models/wizard.rb
class Wizard
# shared instance methods go here
def self.all_visible_subwizards
descendants.entries.select{|d| d.visible?}.sort
end
end
# lib/wizard_fields.rb
module WizardFields
def self.included(base)
base.class_eval do
property :id, DataMapper::Property::Serial
property :state, String
end
end
end
# app/models/foo_wizard.rb
class FooWizard < Wizard
include DataMapper::Resource
include WizardFields
# some associations here
class << self
def description
"foo wizard"
end
def visible?
true
end
end
# state machine logic down here, other methods
end
# app/models/bar_wizard.rb
class BarWizard < Wizard
include DataMapper::Resource
include WizardFields
# some associations here
class << self
def description
"bar wizard"
end
def visible?
true
end
end
# state machine logic down here, other methods
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment