Adds belongs_to_enum to ActiveRecord, which allows you to belong to a .net style enum.
Ruby
Switch branches/tags
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
.gitignore
.rspec
Gemfile
README
Rakefile
belongs_to_enum.gemspec

README

Adds support for transparent enums to ActiveRecord.
Adds a belongs_to_enum to ActiveRecord that takes an array of possible values.

Usage
---------
Use in Rails 3 app. Add to bundler:
gem "belongs_to_enum"

Tests
---------
Uses rspec for testing.
Run tests with rspec spec/*

Todo
---------
* Add scopes

Example
---------

Usage:

    In models:
        scope :admin, where(:role_id => User::Role.admin)
    
    In views:
        =f.select(:role, User::Role.pretty_items)
        -User::Role.each do |role_title, role_id|
            #{role_title} (#{role_id})
        
Classes:
    class User < ActiveRecord::Base
      belongs_to_enum :role, [:normal, :admin, :superadmin, :suspended]
    end

Database Schema:

    create_table :users do |t|
      t.float :role_id
    end