Class: AWS::Record::FormatValidator
Constant Summary
collapse
- ACCEPTED_OPTIONS =
[
:with, :without,
:message, :allow_nil, :on, :if, :unless,
]
Instance Attribute Summary
Attributes inherited from Validator
#attribute_names, #options
Instance Method Summary
collapse
Methods inherited from Validator
#initialize, #validate
Instance Method Details
#message ⇒ Object
50
51
52
|
# File 'lib/aws/record/validators/format.rb', line 50
def message
options[:message] || 'is invalid'
end
|
#setup(record_class) ⇒ Object
27
28
29
30
|
# File 'lib/aws/record/validators/format.rb', line 27
def setup record_class
ensure_type(Regexp, :with, :without)
ensure_at_least_one(:with, :without)
end
|
#validate_attribute(record, attribute_name, value_or_values) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/aws/record/validators/format.rb', line 32
def validate_attribute record, attribute_name, value_or_values
each_value(value_or_values) do |value|
if options[:with]
unless value.to_s =~ options[:with]
record.errors.add(attribute_name, message)
end
end
if options[:without]
unless value.to_s !~ options[:without]
record.errors.add(attribute_name, message)
end
end
end
end
|