Created
October 28, 2009 01:38
-
-
Save therealadam/220153 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# attribute_mapper is a plugin I worked on a little at FiveRuns | |
# and later extracted because I think it's rad. It's a better way to do | |
# enumerated values in your models. | |
# | |
# I'm giving it a little love this week. One of the things I'd like to do is | |
# make it a little cleaner vis a vis contemporary Ruby coding practice. One | |
# of the changes I'd like to make is to switch to explicitly including | |
# attribute_mapper in models that use it, rather than having it inject itself | |
# into every model in your app. | |
# | |
# What do you think? Tweet your choice (option A or B) to @therealadam. | |
# Option A: Rely on plugin init to put the eggs in the basket | |
class Ticket < ActiveRecord::Base | |
map_attribute :status, :to => {:open => 1, :closed => 2} | |
end | |
# Option B: Explicitly include attribute mapper | |
class Ticket < ActiveRecord::Base | |
include AttributeMapper | |
map_attribute :status, :to => {:open => 1, :closed => 2} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment