Class: Varify::Rules::OneOfRule

Inherits:
Rule
  • Object
show all
Defined in:
lib/varify/rules/one_of.rb

Instance Method Summary collapse

Methods inherited from Rule

#initialize

Constructor Details

This class inherits a constructor from Varify::Rules::Rule

Instance Method Details

#error_messageObject



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/varify/rules/one_of.rb', line 10

def error_message
  message = if @options.count >=2
    last  = "'#{@options[-1]}'"
    first = @options[0..-2].map{|o| "'#{o}'"}.join(', ')
    "#{@name} (:#{@key}) must be #{first} or #{last}"
  elsif @options.count == 1
    "#{@name} (:#{@key}) must be '#{@options[0]}'"
  else
    "#{@name} (:#{@key}) can't be valid because no valid options were provided"
  end
  message
end

#valid?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/varify/rules/one_of.rb', line 6

def valid?
  @options.include?(@value)
end