frequency.rb 845 B

1234567891011121314151617181920212223242526272829
  1. class Frequency < ActiveRecord::Base
  2. attr_accessible :delay, :description, :helpmsg, :name, :prefix, :activate
  3. # Relation
  4. has_many :bans, :dependent => :destroy, :inverse_of => :frequency
  5. accepts_nested_attributes_for :bans, :allow_destroy => true
  6. # Validation
  7. validates :name,
  8. :uniqueness => true,
  9. :presence => true,
  10. :format => { :with => /\A-.+-\z/, :message => "Frequency name must begin and end with -" }
  11. validates :prefix,
  12. :uniqueness => true,
  13. :presence => true,
  14. :format => { :with => /\A\..+\z/, :message => "Frequency call prefix must begin with ." }
  15. validates :delay,
  16. :presence => true
  17. before_destroy :raise_if_last
  18. def raise_if_last
  19. if Frequency.count < 3
  20. raise "Can't delete last two frequencies"
  21. end
  22. end
  23. end