Classy Inheritance

Get Version

0.2.0

“You stay classy, inheritance” – Gibson

Consolidation of information

Maintaining this page, the wiki at GitHub, the Google Group and no issue tracker is not an ideal setup. So, everything is moving to stonean.com where I’m giving Redmine a shot a running everything for me. I’ll be posting release announcements to the news feed for each project and keeping the docs up-to-date. Hopefully this will be better for everyone.

Thanks for your interest in Classy Inheritance,
-andy

What

For now, Classy Inheritance adds a depends_on class method to your ActiveRecord model so that you can define requisite objects. More functionality coming for optional relationships.

You can define the relationship to be polymorphic:
class Picture < ActiveRecord::Base
  depends_on :image, :attrs => [:filename, :height, :width], :as => "imageable" 
end

This will look for “imageable_type” and “imageable_id” on the images table add set them accordingly.

Or you can define a standard belongs_to relationship:
class User < ActiveRecord::Base
  depends_on :profile, :attrs => [:first_name, :last_name, :email]
end

What does it do for me?

Well, for starters you get pass-through methods added to your model. So, in the above User example you would get the following:

  @user.first_name
  @user.last_name
  @user.email
  @user.first_name=
  @user.last_name=
  @user.email=

This means you can use these attributes on your form and in your controller instead of having to worry about creating/updating a separate Profile model.

For the above example, you’ll also get a “find_with_profile” class method that will do the :include => :profile addition to your find call for you.

Installing

$ sudo gem install classy-inheritance

# in environment.rb add:
require "classy-inheritance" 

How to submit patches

The Clone URL: git://github.com/stonean/classy-inheritance.git

Read the 8 steps for fixing other people’s code and for section 8b: Submit patch to Google Groups, use the Google Group above.

I’m new to git and this whole opensource project admin gig, so please be patient with my stumbling around.

License

This code is free to use under the terms of the MIT license.

Andrew Stone, 2nd June 2008
Theme extended from Paul Battley