Class: UniqueDJValidator

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
lib/dj_remixes/unique_validator.rb

Overview

Rails 3 style validation:

Instance Method Summary collapse

Instance Method Details

#validate(record) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'lib/dj_remixes/unique_validator.rb', line 3

def validate(record)
  
  if record.payload_object.respond_to?(:unique?) && record.new_record?
    if record.payload_object.unique?
      if DJ.where(:worker_class_name => record.payload_object.worker_class_name, :finished_at => nil).count > 0
        record.errors.add(:base, "Only one #{record.payload_object.worker_class_name} can be queued at a time!")
      end
    end
  end
end