Class: HaveAPI::Validators::Acceptance

Inherits:
HaveAPI::Validator show all
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

#message, #params

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

#describeObject



29
30
31
32
33
34
# File 'lib/haveapi/validators/acceptance.rb', line 29

def describe
  {
      value: @value,
      message: @message,
  }
end

#setupObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/haveapi/validators/acceptance.rb', line 18

def setup
  if simple?
    @value = take

  else
    @value = take(:value)
  end

  @message = take(:message, "has to be #{@value}")
end

#valid?(v) ⇒ Boolean

Returns:



36
37
38
# File 'lib/haveapi/validators/acceptance.rb', line 36

def valid?(v)
  v == @value
end