No commit activity in last 3 years
No release in over 3 years
Gem which will treat its association as its attribute. It will provide getter, setter method for all of its association for which it is defined.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies
 Project Readme

Act As Attribute

Gem for making getter, setter method for a model from its association.

Installation

Add to Gemfile run bundle install:

# Gemfile
gem 'act_as_attribute'

Usage

if we are having two models user and book. In user we have declare:

class User < ActiveRecord::Base
  AVAILABLE_ATTRIBUTES = ["english", "hindi", "social", "science", "math"]
  ACCEPTANCE_LEVEL = "error"
  has_many :books
  act_as_attribute :books, "name", "description"
end

and the book.rb is something like this:

class Book < ActiveRecord::Base
  belongs_to :user
end

Now every user object will have a getter and setter method for 'name' attribute of book object and the value for it will be the 'description' attribute. These methods are created only if they are present in the array 'AVAILABLE_ATTRIBUTES' which is defined in the model as above. and the 'ACCEPTANCE_LEVEL' indicates how to deal if model is already having the same attribute as of method. If it is defined as 'error' then it will raise an exception otherwise it will just give a warning before creating.