Skip to content

store virtual attributes in serialized meta column and track changes

License

Notifications You must be signed in to change notification settings

garshyn/meta_field

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Meta Field

Ruby On Rails serialization gem that supports ActiveModel::Dirty interface to track changes.

Usage

  1. 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
  1. Declare which fields are serialized in meta column
class Record < ActiveRecord::Base
  has_meta_fields :field1, :field2

end
  1. 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' }

Installation

Add this line to your application's Gemfile:

gem 'meta_field', git: 'https://github.com/garshyn/meta_field'

And then execute:

$ bundle

Running the tests

Checkout the repo the then run

rspec

Built With

  • ActiveRecord

Contributing

Contributions are welcome

Versioning

We use SemVer for versioning.

Authors

License

The gem is available as open source under the terms of the MIT License.

About

store virtual attributes in serialized meta column and track changes

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages