HStore Flags

Gem Version License Build Status Code Climate Test Coverage

integer/bit flags aggrevating you? try this.

Requirements

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 to flags
  • scopes: false disables scope creation. though im not sure how useful that is

Contributors