class RailsBestPractices::Reviews::UseMultipartAlternativeAsContentTypeOfEmailReview

Make sure to use multipart/alternative as content_type of email.

See the best practice details here rails-bestpractices.com/posts/2010/08/05/use-multipart-alternative-as-content_type-of-email/

Implementation:

Review process:

check class node to remember the class name,
and check the method definition nodes to see if the corresponding mailer views exist or not.

Private Instance Methods

mailer_directory() click to toggle source

the view directory of mailer.

# File lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb, line 57
def mailer_directory
  File.join(Core::Runner.base_path, "app/views/#{@klazz_name.to_s.underscore}")
end
mailer_files(name) click to toggle source

all mail view files for a method name.

# File lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb, line 52
def mailer_files(name)
  Dir.entries(mailer_directory) { |filename| filename.index name.to_s }
end
rails3_canonical_mailer_views?(name) click to toggle source

check if rails3’s syntax mailer views are canonical.

@param [String] name method name in action_mailer

# File lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb, line 43
def rails3_canonical_mailer_views?(name)
  return true if mailer_files(name).empty?
  return true if mailer_files(name).none? { |filename| filename.index 'html' }

  mailer_files(name).any? { |filename| filename.index 'html' } &&
    mailer_files(name).any? { |filename| filename.index 'text' }
end
rails_canonical_mailer_views?(name) click to toggle source

check if rails’s syntax mailer views are canonical.

@param [String] name method name in action_mailer

# File lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb, line 38
def rails_canonical_mailer_views?(name); end