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
29 30 31 32 33 34 |
# File 'lib/haveapi/validators/acceptance.rb', line 29 def describe { value: @value, message: @message } end |
#setup ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/haveapi/validators/acceptance.rb', line 18 def setup @value = if simple? take else take(:value) end @message = take(:message, "has to be #{@value}") end |
#valid?(v) ⇒ Boolean
36 37 38 |
# File 'lib/haveapi/validators/acceptance.rb', line 36 def valid?(v) v == @value end |