Class: HaveAPI::Validators::Exclusion
- Inherits:
-
HaveAPI::Validator
- Object
- HaveAPI::Validator
- HaveAPI::Validators::Exclusion
- Defined in:
- lib/haveapi/validators/exclusion.rb
Overview
Checks that the value is not reserved.
Short form:
string :param, exclude: i(one two three)
Full form:
string :param, exclude: {
values: i(one two three),
message: 'the error message'
}
In this case, the value could be anything but one, two or
three.
Instance Attribute Summary
Attributes inherited from HaveAPI::Validator
Instance Method Summary collapse
Methods inherited from HaveAPI::Validator
#initialize, name, #reconfigure, takes, use, use?, #useful?, #validate
Constructor Details
This class inherits a constructor from HaveAPI::Validator
Instance Method Details
#describe ⇒ Object
27 28 29 30 31 32 |
# File 'lib/haveapi/validators/exclusion.rb', line 27 def describe { values: @values, message: , } end |
#setup ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/haveapi/validators/exclusion.rb', line 19 def setup @values = (simple? ? take : take(:values)).map! do |v| v.is_a?(::Symbol) ? v.to_s : v end = take(:message, '%{value} cannot be used') end |
#valid?(v) ⇒ Boolean
34 35 36 |
# File 'lib/haveapi/validators/exclusion.rb', line 34 def valid?(v) !@values.include?(v) end |