xmlblog (owner)

Revisions

gist: 141893 Download_button fork
public
Public Clone URL: git://gist.github.com/141893.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Hmmm, not sure I like it
# not much of an improvement
 
class Thing < AR::Base
  StateMap = Hash.new {|h,k| h[k] = @@states[3]}.update({
    'disabled' => @@states[0..1],
    'active' => @@states[2],
    'all' => nil
  })
  
  def self.find_by_f(f)
    find(:all, state_predicate(f.to_s))
  end
   
  private
 
  def state_predicate(f, opts={})
    StateMap[f] ? { :conditions => { :state => StateMap[f] } : {}
  end
end