ABANDON NOTICE
This gem is no longer maintained. Rails Core supports HStore and JSON fields directly. You should no longer need this Gem if you are using a newer version of Rails.
HStore Flags
integer/bit flags aggrevating you? try this.
Requirements
- Rails 4.0 or greater
- Postgresql 8.4+ with contrib package
- Read activerecord-postgres-hstore for index creation
Installation
TODO
Usage
# Add hstore flags column to your table in a migration
def change
add_column :shipments, :flags, :hstore
end
# defining flags
class User < ActiveRecord::Base
hstore_flags :active, :admin
hstore_flags :customer, :vendor, :drop_ship, field: "user_type"
end
class Group < ActiveRecord::Base
hstore_flags :active, :public, :invite_only, scopes: false
end
# setting flags
u = User.new
u.active = true
u.vendor = false
# automatic scope creation
User.active.to_sql #=> SELECT * FROM users WHERE (defined(flags, 'active') IS TRUE)
User.not_drop_ship.to_sql #=> SELECT * FROM users WHERE (defined(user_type, 'drop_ship') IS NOT TRUE)
-
field
option defaults toflags
-
scopes: false
disables scope creation. though im not sure how useful that is