V(irtual)attributes
Makes virtual attributes easier.
Instalation
Add this line to your application's Gemfile:
gem 'vattributes'
And then execute:
$ bundle
Usage
Add the vattributes field to the table as a text and run the migration:
rails g migration AddVattributesToPosts vattributes:text
rake db:migrate
class Post < ActiveRecord::Base
vattributes :permalink
validates :permalink, presence: true
end
If you ever need to overrite a setter, or getter, you can do like follows:
class Post < ActiveRecord::Base
vattributes :tags, :permalink
def tags=(array)
set_vattribute(:tags, array.join(','))
end
def tags
get_vattribute(:tags).split(',')
end
end
Authors
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
** Do not forget to write tests**