Class: HaveAPI::Validators::Acceptance
- Inherits:
-
HaveAPI::Validator
- Object
- HaveAPI::Validator
- HaveAPI::Validators::Acceptance
- Defined in:
- lib/haveapi/validators/acceptance.rb
Overview
Accepts a single configured value.
Short form:
string :param, accept: 'value'
Full form:
string :param, accept: {
value: 'value',
message: 'the error message'
}
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/acceptance.rb', line 27 def describe { value: @value, message: , } end |
#setup ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/haveapi/validators/acceptance.rb', line 16 def setup if simple? @value = take else @value = take(:value) end = take(:message, "has to be #{@value}") end |
#valid?(v) ⇒ Boolean
34 35 36 |
# File 'lib/haveapi/validators/acceptance.rb', line 34 def valid?(v) v == @value end |