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