No commit activity in last 3 years
No release in over 3 years
ActiveRecord meta attributes that are mapped to a single (or multiple) hstore columns in postgres
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

HstoreAttributes

Build Status Code Climate

HstoreAttributes is a small extension on top of activerecord-postgres-hstore, which creates "fake" attributes that map into the hstore hash. By defining these attributes you get automatic validations and type casting. The approach is very similar to the ActiveRecord::Store feature, yielding better query and index performance in comparison to simple hash-to-yml-string usage.

A small example:

class Product < ActiveRecord::Base

  # serialize as hstore (not needed for activerecord-postgres-hstore < 0.7)
  serialize :properties, ActiveRecord::Coders::Hstore

  # define attributes with types to be mapped into the hstore
  hstore :properties, :accessors => { :width => :integer, :height => :integer, :color => :string }

  # if you want to dump strings only:
  hstore :properties, :accessors => [:color, :other_property, :third_property]

  validates_numericality_of :weight

  #  ...
end

Installation

Add this line to your application's Gemfile:

gem 'hstore-attributes'

And then execute:

$ bundle

Or install it yourself as:

$ gem install hstore-attributes

Usage

Usage should be pretty straightforward as shown in the example. Be sure to create a hstore column that takes the mapped attributes. Please note that this works for postgresql databases only.

See: https://github.com/softa/activerecord-postgres-hstore

Contributing

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