Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Adds support for enumerable types to ActiveRecord

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 init.rb
README.rdoc

active-record-enumerable

Installation

script/plugin install git://github.com/ddollar/active-record-enumerable.git

Usage

class Food < ActiveRecord::Base
  include ActiveRecordEnumerable

  enumerate :type,  :as => %w( fruit vegetable ), :default => 'fruit'
  enumerate :color, :as => %w( red green )
end

Example

>> f = Food.new
=> #<Food id: nil, type: "foo", color: "red">
>> f.save
=> true

>> f.color.red?
=> true

>> f.color.turquoise?
=> false

>> f.update_attributes!(:color => "random")
=> ActiveRecord::RecordInvalid: Validation failed: Color is not included in the list

MIT License

Something went wrong with that request. Please try again.