Skip to content

dovadi/has_attributes_from

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Has_attributes_from

Download: http://github.com/dovadi/has_attributes_from or clone

  • git clone git://github.com/dovadi/has_attributes_from.git

Description:

Merge the attributes from another ActiveRecord class to an individual STI subclass.

Example:

create_table "child_details", :force => true do |t|
  t.string   "nickname"
  t.string   "allergy"
  t.integer  "child_id" :belongs_to :child
end

create_table "caretaker_details", :force => true do |t|
  t.string   "relation"
  t.integer  "caretaker_id" #belongs_to :caretaker
end

create_table "people", :force => true do |t|
  t.string   "type"
  t.string   "firstname"
  t.string   "lastname"
  t.string   "email"
end

class Person < ActiveRecord::Base
end

class Child < Person
  has_attributes_from :child_details
  validates_presence_of :nickname
end

class Caretaker < Person
  has_attributes_from :caretaker_details
end

child = Child.create(:firstname =>'William', :lastname=>'Gates' :email=>'bgates@microsoft.com', :nickname=>'Bill')
child.update_attributes(:allergy=>'Not allowed to eat apples!')

caretaker = Caretaker.create(:firstname =>'William H.', :lastname=>'Gates' :email=>'w.h.gates@gmail.com')
caretaker.update_attribute(:relation, 'Daddy')

Install:

As a gem:

*  sudo gem install dovadi-has_attributes_from -s http://gems.github.com or
*  Add the following to your environment.rb:

config.gem 'dovadi-has_attributes_from',
           :lib => 'has_attributes_from',
           :version => '>=0.1.1',
           :source => 'http://gems.github.com'

As a plugin:

*  ./script/plugin install git://github.com/dovadi/has_attributes_from.git

Test

  • You can run the tests from this gem with rake test:default (you need to install the Shoulda and Factory_girl gems).

Credits

This project is funded and maintained by Agile Dovadi BV, contact Frank Oxener

Licence:

(The MIT License)

Copyright (c) 2009 Frank Oxener - Agile Dovadi B.V.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Merge the attributes from another ActiveRecord class to an individual STI subclass

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages