Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Easy delegation of all columns of an ActiveRecord association

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .rspec
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 Gemfile
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 delegate_all_for.gemspec
README.md

DelegateAllFor

Build Status

The primary driver for creating this gem was to create an easy way to accomplish the Multiple Table Inheritance pattern in active record. delegate_all_for allows for easy delegation of all the columns of an ActiveRecord association, including the getter, setter, and predicate for each column.

Usage

class Parent < ActiveRecord::Base
  has_one :child
  # columns: name
  delegate_all_for :child, except: [:sort], also_include: [:extra_method], allow_nil: true
end

class Child < ActiveRecord::Base
  belongs_to :parent
  # columns: name, description, sort
  def extra_method; 'a little extra' end
end

Parent.new.description # Delegated to Child
Parent.new.description? # Delegated to Child
Parent.new.description= # Delegated to Child
Parent.new.extra_method # Delegated to Child
Parent.new.name # Still comes from Parent
Parent.new.sort # method_missing

Installation

Add this line to your application's Gemfile:

gem 'delegate_all_for'

And then execute:

$ bundle

Or install it yourself as:

$ gem install delegate_all_for

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Credits

Something went wrong with that request. Please try again.