therealadam (owner)

Revisions

gist: 220153 Download_button fork
public
Public Clone URL: git://gist.github.com/220153.git
Embed All Files: show embed
attribute_mapper_poll.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 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