Ruby On Rails serialization gem that supports ActiveModel::Dirty
interface to track changes.
- Have a
meta
column in the database table
class AddMetaToRecords < ActiveRecord::Migration
def change
add_column :records, :meta, :text, limit: 1.megabyte - 1
end
end
- Declare which fields are serialized in
meta
column
class Record < ActiveRecord::Base
has_meta_fields :field1, :field2
end
- Use
field1
setter and getter as it is a regular record attribute.
record = Record.new field1: 'value1'
record.field1 # => 'value1'
record.field1 = 'value2' # => 'value2'
record.save # saved to `meta` column as { 'field1' => 'value2' }
Add this line to your application's Gemfile:
gem 'meta_field', git: 'https://github.com/garshyn/meta_field'
And then execute:
$ bundle
Checkout the repo the then run
rspec
- ActiveRecord
Contributions are welcome
We use SemVer for versioning.
- Andrew Garshyn - garshyn
The gem is available as open source under the terms of the MIT License.