Stores and retrieves delegatable data through attributes on a ActiveRecord class, with support for translatable attributes.
Add this line to your application's Gemfile:
gem'active_delegate'And then execute:
$ bundle
Or install it yourself as:
$ gem install active_delegate
classAddress < ActiveRecord::Base# columns: :city, :districtendclassPerson < ActiveRecord::Base# columns: :name, email, :phone, :address_idincludeActiveDelegatebelongs_to:addresshas_one:userhas_many:booksdelegate_attributesto: :address,prefix: true,localized: trueendparams={name: 'John',email: 'john@mail.com',address_city: 'Athens',address_city_el: 'Αθήνα',address_district: 'Attiki',address_district_el: 'Αττική'}person=Person.new(params)person.name# 'John'person.address_city# 'Athens'person.address.city# 'Athens'person.address_city_el# 'Αθήνα'person.address.city_el# 'Αθήνα'person.address_district# 'Attiki'person.address.district# 'Attiki'person.address_district_el# 'Αττική'person.address.district_el# 'Αττική'classUser < ActiveRecord::Base# columns: :login, :password, :person_idincludeActiveDelegatebelongs_to:person,autosave: truedelegate_associationsto: :persondelegate_attributesto: :personendparams={login: 'jonian',password: 'passwd',name: 'John',email: 'john@mail.com'}user=User.new(params)user.name# 'John'user.login# 'jonian'user.user# @useruser.books# []user.email# 'john@mail.com'user.email?# trueuser.email_changed?# trueuser.email_was# nilAfter checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment. To install this gem onto your local machine, run bundle exec rake install.
Bug reports and pull requests are welcome on GitHub at https://github.com/hardpixel/active-delegate.
The gem is available as open source under the terms of the MIT License.