Class: Audiothority::Validators::Unique
- Inherits:
-
Object
- Object
- Audiothority::Validators::Unique
- Defined in:
- lib/audiothority/validators/unique.rb
Instance Method Summary collapse
-
#initialize(thing) ⇒ Unique
constructor
A new instance of Unique.
- #validate(tags) ⇒ Object
Constructor Details
#initialize(thing) ⇒ Unique
Returns a new instance of Unique.
6 7 8 |
# File 'lib/audiothority/validators/unique.rb', line 6 def initialize(thing) @thing = thing end |
Instance Method Details
#validate(tags) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/audiothority/validators/unique.rb', line 10 def validate() items = .map { |t| t.send(@thing) }.uniq if items.one? Validation.new elsif items.compact.empty? Violation.new(@thing, :missing, %(missing #{@thing} field)) elsif items.size > 1 Violation.new(@thing, :multiple, %(multiple #{@thing}s: #{items.map(&:inspect).join(', ')})) end end |