Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'active_record'
- class Document < ActiveRecord::Base
- named_scope :by_state, lambda { |state| {:conditions => ['orders.state = ?',state]} }
- STATES = %w{queued working finished failed}.freeze
- STATES.each do |state|
- define_method("#{state}?") { self.state == state }
- end
- end
- documents = Document.by_state('working').find(:all)
- documents.each do |doc|
- doc.state #=> 'working'
- doc.working? #=> true
- doc.finished? #=> false
- end
Add Comment
Please, Sign In to add comment