forked from code-later/has_enum
-
Notifications
You must be signed in to change notification settings - Fork 0
caroo/has_enum
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
= HasEnum The has_enum extension provides an association with an enumeration class which requires the renum gem (sudo gem install renum). *Note*: We prefer to use the caroo renum fork: git@github.com:caroo/has_enum.git == Installation You have to make sure to have a column in your database table to store the string representation of the associated enum instance. The plugin will look by default for a column named like the enum itself plus the "_type" suffix. == Example # Class that has an Enumartion associated class Customer < ActiveRecord::Base has_enum :customer_state # needs customer_state_type column in database end customer = Customer.new # Before setting any enum customer.customer_state # => nil customer.customer_state_type # => "" customer.customer_state = CustomerState::Premium customer.customer_state # => CustomerState::Premium customer.customer_state_type # => "Premium" customer.customer_state_has_changed? # => true # Define the Enum-Class. # For more information have a look at the renum gem enum :CustomerState do attr_reader :monthly_due Free(0) Basic(5.95) Premium(19.95) def init(monthly_due) monthly_due = monthly_due end end premium_state = CustomerState::Premium premium_state.monthly_due # => 19.95 Copyright (c) 2008 [Dirk Breuer, Alexander Gräfe and Ethem Küçük]
About
No description, website, or topics provided.
Resources
Stars
Watchers
Forks
Packages 0
No packages published
Languages
- Ruby 100.0%