Class: EmailValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- EmailValidator
- Defined in:
- lib/email_parser/validator.rb
Class Attribute Summary collapse
-
.default_parser_options ⇒ Object
Returns the value of attribute default_parser_options.
Instance Method Summary collapse
-
#initialize(*_args) ⇒ EmailValidator
constructor
A new instance of EmailValidator.
- #validate_each(record, attribute, value) ⇒ Object
Constructor Details
#initialize(*_args) ⇒ EmailValidator
Returns a new instance of EmailValidator.
11 12 13 14 15 16 17 |
# File 'lib/email_parser/validator.rb', line 11 def initialize(*_args) super = .each_with_object({}) do |(k, v), h| h[k] = v if EmailParser::OPTIONS.include?(k) end @parser = EmailParser.new(**self.class..merge()) end |
Class Attribute Details
.default_parser_options ⇒ Object
Returns the value of attribute default_parser_options.
6 7 8 |
# File 'lib/email_parser/validator.rb', line 6 def @default_parser_options end |
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/email_parser/validator.rb', line 19 def validate_each(record, attribute, value) if value.nil? return if [:allow_nil] record.errors.add(attribute, :blank) return end return if @parser.valid?(value) record.errors.add(attribute, :invalid) end |