Class: Rulix::Validators::OneOfValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/rulix/validators/one_of_validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = nil) ⇒ OneOfValidator

Returns a new instance of OneOfValidator.



6
7
8
9
# File 'lib/rulix/validators/one_of_validator.rb', line 6

def initialize options = nil
  options ||= []
  self.options = options
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/rulix/validators/one_of_validator.rb', line 4

def options
  @options
end

Instance Method Details

#call(value) ⇒ Object



11
12
13
# File 'lib/rulix/validators/one_of_validator.rb', line 11

def call value
  (value && options.include?(value)) || [false, "is not one of #{options}"]
end

#to_procObject



15
16
17
# File 'lib/rulix/validators/one_of_validator.rb', line 15

def to_proc
  method(:call)
end