Class: AWS::Record::ExclusionValidator

Inherits:
InclusionValidator show all
Defined in:
lib/aws/record/validators/exclusion.rb

Constant Summary collapse

ACCEPTED_OPTIONS =
[:in, :message, :allow_nil, :on, :if, :unless]

Instance Attribute Summary

Attributes inherited from Validator

#attribute_names, #options

Instance Method Summary collapse

Methods inherited from InclusionValidator

#value_included?

Methods inherited from Validator

#initialize, #validate

Constructor Details

This class inherits a constructor from AWS::Record::Validator

Instance Method Details

#messageObject



36
37
38
# File 'lib/aws/record/validators/exclusion.rb', line 36

def message
  options[:message] || 'is reserved'
end

#setup(record_class) ⇒ Object



24
25
26
27
# File 'lib/aws/record/validators/exclusion.rb', line 24

def setup record_class
  ensure_present(:in)
  ensure_type(Enumerable, :in)
end

#validate_attribute(record, attribute_name, value_or_values) ⇒ Object



29
30
31
32
33
34
# File 'lib/aws/record/validators/exclusion.rb', line 29

def validate_attribute record, attribute_name, value_or_values
  each_value(value_or_values) do |value|
    included = value_included?(value)
    record.errors.add(attribute_name, message) if included 
  end
end