ar_protobuf_store

Gem Version Build Status MIT license

Description

Rails/ActiveRecord 3 comes with a cool ActiveRecord::Store feature that allows for creating a fairly lightweight schema-less model. However, it uses YAML, which has poor performance and is just generally silly.

This gem enhances ActiveRecord to allow storing values in a binary Protocol Buffer blob. This adds a degree of type-safety and schema management without having to deal with the migration pain of adding and removing columns to a regular SQL table. (As well as removing the possibility of indexing the internal values.)

This gem is known to work with the three "major" Ruby Protocol Buffer libraries (here listed in descending order of speed):

Install

$ gem install ar_protobuf_store

Examples

You can call ar_protobuf_store similarly to how you would previously have called store:

class FooExtras < ::Protobuf::Message
  # Auto-generated protobuf compiler output here!
end

# FooModel would have a schema like:
# create_table :foo_model do |t|
#   # Recommend setting a limit that's biggish so it will be stored as a binary
#   # blob by MySQL instead of a binary varchar.
#   t.binary :extras, :limit => 1.megabyte
# end
class FooModel < ActiveRecord::Base
  # The old, YAML-based version would look like:
  # store :extras, :accessors => :foo, :bar

  # The new, protobuf-based version would look like:
  protobuf_store :extras, FooExtras
end

Requirements

Copyright (c) 2014 Hsiu-Fan Wang

See LICENSE for details.