Class: HaveAPI::Validators::Confirmation
- Inherits:
-
HaveAPI::Validator
- Object
- HaveAPI::Validator
- HaveAPI::Validators::Confirmation
- Defined in:
- lib/haveapi/validators/confirmation.rb
Overview
Checks that two parameters are equal or not equal.
Short form:
string :param, confirm: :other_parameter
Full form:
string :param, confirm: {
param: :other_parameter,
equal: true/false,
message: 'the error message'
}
‘equal` defaults to `true`.
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
30 31 32 33 34 35 36 |
# File 'lib/haveapi/validators/confirmation.rb', line 30 def describe { equal: @equal ? true : false, parameter: @param, message: @message } end |
#setup ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/haveapi/validators/confirmation.rb', line 21 def setup @param = simple? ? take : take(:param) @equal = take(:equal, true) @message = take( :message, @equal ? "must be the same as #{@param}" : "must be different from #{@param}" ) end |
#valid?(v) ⇒ Boolean
38 39 40 41 42 43 44 45 |
# File 'lib/haveapi/validators/confirmation.rb', line 38 def valid?(v) if @equal v == params[@param] else v != params[@param] end end |