Skip to content

Commit

Permalink
Added is_a_superclass. Thanks again Eric!
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://svn0.sea.apvio.net/home/rwl4/inherits_from@5 bd10a536-b517-0410-99c0-c9a68740b5c0
  • Loading branch information
rwl4 committed Apr 25, 2007
1 parent 71c5092 commit d1708e1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/inherits_from.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,18 @@ def self.inherits_from(association_id, options = {})
before_update(before_callback)
end

def self.is_a_superclass
define_method('subobject') do
subtype.constantize.send("find_by_#{self.class.name.downcase}_id", send("id"))
end
end

private
# Ensures that there is an association to access, if not, creates one.
def init_inherited_assoc(association_id)
if new_record? and instance_variable_get("@#{association_id}").nil?
send("build_#{association_id}")
instance_variable_get("@#{association_id}").type = self.class.to_s
instance_variable_get("@#{association_id}").subtype = self.class.to_s
end
end
end

0 comments on commit d1708e1

Please sign in to comment.