Class: Maildis::Validator
- Inherits:
-
Object
- Object
- Maildis::Validator
- Defined in:
- lib/maildis/validator.rb
Class Method Summary collapse
- .validate_config(hash) ⇒ Object
- .validate_recipients(hash) ⇒ Object
- .validate_sender(hash) ⇒ Object
- .validate_smtp(hash) ⇒ Object
- .validate_subject(subject) ⇒ Object
- .validate_templates(hash) ⇒ Object
Class Method Details
.validate_config(hash) ⇒ Object
11 12 13 14 |
# File 'lib/maildis/validator.rb', line 11 def validate_config(hash) raise ValidationError, "mailer settings missing" unless hash.has_key? 'mailer' raise ValidationError, "smtp settings missing" unless hash.has_key? 'smtp' end |
.validate_recipients(hash) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/maildis/validator.rb', line 32 def validate_recipients(hash) raise ValidationError, "recipients::csv missing" unless hash.has_key? 'csv' raise ValidationError, "recipients::csv invalid file path" unless File.exist?(File.(hash['csv'])) raise ValidationError, "recipients::csv empty" if RecipientParser.empty_csv? hash['csv'] raise ValidationError, "recipients::csv invalid column headers" unless RecipientParser.valid_csv? hash['csv'] end |
.validate_sender(hash) ⇒ Object
27 28 29 30 |
# File 'lib/maildis/validator.rb', line 27 def validate_sender(hash) raise ValidationError, "sender::name missing" unless hash.has_key? 'name' raise ValidationError, "sender::email missing or invalid" unless hash.has_key?('email') && ValidationUtils.valid_email?(hash['email']) end |
.validate_smtp(hash) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/maildis/validator.rb', line 20 def validate_smtp(hash) raise ValidationError, "smtp::host missing or invalid" unless hash.has_key?('host') && ValidationUtils.valid_hostname?(hash['host']) raise ValidationError, "smtp::port missing or invalid" unless hash.has_key?('port') && (hash['port'].to_i != 0) raise ValidationError, "smtp::username missing" unless hash.has_key? 'username' raise ValidationError, "smtp::password missing" unless hash.has_key? 'password' end |
.validate_subject(subject) ⇒ Object
16 17 18 |
# File 'lib/maildis/validator.rb', line 16 def validate_subject(subject) raise ValidationError, "mailer::subject invalid" unless !subject.nil? && !subject.empty? end |
.validate_templates(hash) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/maildis/validator.rb', line 39 def validate_templates(hash) raise ValidationError, "templates::html not specified" unless hash.has_key? 'html' raise ValidationError, "templates::plain not specified" unless hash.has_key? 'plain' raise ValidationError, "templates::html not found" unless File.exist?(File.(hash['html'])) raise ValidationError, "templates::plain not found" unless File.exist?(File.(hash['plain'])) end |