Virtualize
Virtualize allows ActiveRecord to have virtual attributes.
Super simple substitute for such as redis-objects
Installation
Add this line to your application's Gemfile:
gem 'virtualize'
And then execute:
$ bundle
Or install it yourself as:
$ gem install virtualize
Usage
Basic:
class Blog < ActiveRecord::Base
include Virtualize
set_virtual_attributes :memo, on: :virtual
end
you MUST add the column named virtual with type TEXT.
@blog = Blog.last
@blog.memo #=> nil
@blog.memo = 'hoge'
@blog.save
@blog.memo #=> 'hoge'
Use standard save or save! methods for persistence.
The form helper and mass assignment are also supported.
= form_for @blog do |f|
= f.text_area :memo
@blog = Blog.find(params[:id])
@blog.update_attributes!(params[:blog].permit!)
Caution
You should not use this function for a lot. This is only for the misc columns.
You should think another way for storing altenate key or the column using for search or order.
Contributing
- Fork it ( https://github.com/[my-github-username]/virtualize/fork )
- 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 a new Pull Request