Class: Mayaml::MailAccount::TypeValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/mayaml/mail_account/type_validator.rb

Constant Summary collapse

VALID_TYPES =
[:imap, :pop3].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ TypeValidator

Returns a new instance of TypeValidator.



26
27
28
29
30
31
32
# File 'lib/mayaml/mail_account/type_validator.rb', line 26

def initialize(type)
  @errors = []
  type = type.to_sym if type.respond_to? :to_sym
  unless VALID_TYPES.include?(type)
    @errors << "Mail account type is invalid. Allowed types: #{VALID_TYPES.join(", ")}."
  end
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



23
24
25
# File 'lib/mayaml/mail_account/type_validator.rb', line 23

def errors
  @errors
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/mayaml/mail_account/type_validator.rb', line 34

def valid?
  @errors.empty?
end