https://github.com/github/serialized_attributes
UNMAINTAINED - kind of a bridge between using AR and a full blown schema-free db
https://github.com/github/serialized_attributes
Last synced: 5 months ago
JSON representation
UNMAINTAINED - kind of a bridge between using AR and a full blown schema-free db
- Host: GitHub
- URL: https://github.com/github/serialized_attributes
- Owner: github
- License: mit
- Archived: true
- Fork: true (technoweenie/serialized_attributes)
- Created: 2013-12-03T21:22:22.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2017-06-21T12:25:36.000Z (over 8 years ago)
- Last Synced: 2024-09-29T00:21:32.690Z (over 1 year ago)
- Language: Ruby
- Homepage:
- Size: 81.1 KB
- Stars: 9
- Watchers: 26
- Forks: 11
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# UNMAINTAINED
This repo is no longer being maintained as of 2015-08-25.
---
# SerializedAttributes
SerializedAttributes allows you to add an encoded hash to an ActiveRecord model.
This is similar to the built-in ActiveRecord serialization, except that the field
is converted to JSON, gzipped, and stored in a BLOB field. This uses the json
gem which is much faster than YAML serialization. However, JSON is not nearly as
flexible, so you're stuck with strings/integers/dates/etc.
Where possible, ActiveRecord compatible methods are generated so that a migration
should be pretty simple. See unit tests for examples.
Some of the code and most of the ideas are taken from [Heresy][Heresy], a ruby
implementation of [how FriendFeed uses MySQL for schema-free storage][schemafree].
Supports ActiveRecord 2.2 in ruby 1.8.7, and ActiveRecord 2.3-3.1 in ruby 1.9.3.
See [Travis CI][travis] to see if we support your version of
ActiveRecord and ruby.
[Heresy]: https://github.com/kabuki/heresy
[schemafree]: http://bret.appspot.com/entry/how-friendfeed-uses-mysql
[travis]: http://travis-ci.org/#!/technoweenie/serialized_attributes
## Setup
Install the plugin into your Rails app.
## Usage
```ruby
class Profile < ActiveRecord::Base
# assumes #data serializes to raw_data blob field
serialize_attributes do
string :title, :description
integer :age
float :rank, :percentage
time :birthday
end
# Serializes #data to assumed raw_data blob field
serialize_attributes :data do
string :title, :description
integer :age
float :rank, :percentage
time :birthday
end
# set the blob field
serialize_attributes :data, :blob => :serialized_field do
string :title, :description
integer :age
float :rank, :percentage
time :birthday
end
end
```