Skip to content

Instantly share code, notes, and snippets.

@christianromney
Forked from technoweenie/gist:141882
Created July 7, 2009 04:54
Show Gist options
  • Save christianromney/141893 to your computer and use it in GitHub Desktop.
Save christianromney/141893 to your computer and use it in GitHub Desktop.
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment