Class: Violated::UniqueValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/violated/validators/unique_validator.rb

Instance Method Summary collapse

Constructor Details

#initialize(_, unique_check) ⇒ UniqueValidator

Returns a new instance of UniqueValidator.



6
7
8
# File 'lib/violated/validators/unique_validator.rb', line 6

def initialize(_, unique_check)
  @unique_check = unique_check
end

Instance Method Details

#reasonObject



10
11
12
# File 'lib/violated/validators/unique_validator.rb', line 10

def reason
  :duplicate
end

#valid?(value) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/violated/validators/unique_validator.rb', line 14

def valid?(value)
  !@unique_check.call(value)
end