Class: ActionMailer::Preview

Inherits:
Object
  • Object
show all
Extended by:
ActiveSupport::DescendantsTracker
Defined in:
actionmailer/lib/action_mailer/preview.rb

Class Method Summary collapse

Methods included from ActiveSupport::DescendantsTracker

clear, descendants, descendants, direct_descendants, direct_descendants, inherited, store_inherited

Class Method Details

.allObject

Returns all mailer preview classes



48
49
50
51
# File 'actionmailer/lib/action_mailer/preview.rb', line 48

def all
  load_previews if descendants.empty?
  descendants
end

.call(email) ⇒ Object

Returns the mail object for the given email name. The registered preview interceptors will be informed so that they can transform the message as they would if the mail was actually being delivered.



56
57
58
59
60
61
# File 'actionmailer/lib/action_mailer/preview.rb', line 56

def call(email)
  preview = self.new
  message = preview.public_send(email)
  inform_preview_interceptors(message)
  message
end

.email_exists?(email) ⇒ Boolean

Returns true if the email exists

Returns:

  • (Boolean)


69
70
71
# File 'actionmailer/lib/action_mailer/preview.rb', line 69

def email_exists?(email)
  emails.include?(email)
end

.emailsObject

Returns all of the available email previews



64
65
66
# File 'actionmailer/lib/action_mailer/preview.rb', line 64

def emails
  public_instance_methods(false).map(&:to_s).sort
end

.exists?(preview) ⇒ Boolean

Returns true if the preview exists

Returns:

  • (Boolean)


74
75
76
# File 'actionmailer/lib/action_mailer/preview.rb', line 74

def exists?(preview)
  all.any?{ |p| p.preview_name == preview }
end

.find(preview) ⇒ Object

Find a mailer preview by its underscored class name



79
80
81
# File 'actionmailer/lib/action_mailer/preview.rb', line 79

def find(preview)
  all.find{ |p| p.preview_name == preview }
end

.preview_nameObject

Returns the underscored name of the mailer preview without the suffix



84
85
86
# File 'actionmailer/lib/action_mailer/preview.rb', line 84

def preview_name
  name.sub(/Preview$/, '').underscore
end