Created
March 19, 2012 18:32
-
-
Save abevoelker/2123152 to your computer and use it in GitHub Desktop.
concrete table inheritance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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