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



32
33
34
35
36
37
# File 'lib/haveapi/validators/acceptance.rb', line 32

def describe
  {
    value: @value,
    message: HaveAPI.localize(@message)
  }
end

#setupObject



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.message('haveapi.validators.acceptance.accepted', value: @value)
  )
end

#valid?(v) ⇒ Boolean

Returns:



39
40
41
# File 'lib/haveapi/validators/acceptance.rb', line 39

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