Class: MiniDefender::Rules::Distinct
Class Method Summary
collapse
Instance Method Summary
collapse
#active?, available?, #bails?, #coerce, #default_value, #defaults?, #error_message, #excluded?, #force_coerce?, #implicit?, make, #priority, #stops?, #with_message
Class Method Details
.signature ⇒ Object
4
5
6
|
# File 'lib/mini_defender/rules/distinct.rb', line 4
def self.signature
'distinct'
end
|
Instance Method Details
#message(attribute, value, validator) ⇒ Object
15
16
17
|
# File 'lib/mini_defender/rules/distinct.rb', line 15
def message(attribute, value, validator)
'The value should be unique.'
end
|
#passes?(attribute, value, validator) ⇒ Boolean
8
9
10
11
12
13
|
# File 'lib/mini_defender/rules/distinct.rb', line 8
def passes?(attribute, value, validator)
validator
.neighbors(attribute)
.reject { |k, v| k == attribute }
.none? { |_, v| v == value }
end
|