Provides auto-serialization of simple Ruby types that databases do not support.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Code Climate Test Coverage Build Status Inline docs Gem Version


Provides helper functionality for ruby classes that store various database-unfriendly types as instance variables. It automatically serializes and deserializes things like classes and symbols to interact easily with both the database and your application code.


Add this line to your application's Gemfile:

gem "attribute_helpers"

And then execute:

$ bundle

Or install it yourself as:

$ gem install attribute_helpers


This gem exposes the attr_symbol and attr_class class methods, which when called will wrap the related instance method to allow for better database serialization.

require "attribute_helpers"

class Vehicle < ActiveRecord::Base
  extend AttributeHelpers

  attr_class :manufacturer
  attr_symbol :status

car =
car.manufacturer = Tesla # This is a class.
car.status = :parked!
car = car.reload # After a DB round-trip, typically these fields are strings.
car.manufacturer # Tesla (the class) rather than "Tesla" (the string)
car.status # :parked (the symbol) rather than "parked" (the string)

Note: while this gem was written to help with ActiveRecord objects, it has no dependencies and works great with any database backend (or none!). You can extend it into pure Ruby classes just fine!


  1. Fork it (
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Make sure your changes have appropriate tests (bundle exec rspec) and conform to the Rubocop style specified. We use overcommit to enforce good code.


AttributeHelpers is released under the MIT License.