Class: ActionMailer::Preview

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ActiveSupport::DescendantsTracker

clear, descendants, descendants, disable_clear!, reject!, store_inherited, subclasses, subclasses

Methods included from ActiveSupport::DescendantsTracker::ReloadedClassesFiltering

#descendants, #subclasses

Constructor Details

#initialize(params = {}) ⇒ Preview

Returns a new instance of Preview.



98
99
100
# File 'actionmailer/lib/action_mailer/preview.rb', line 98

def initialize(params = {})
  @params = params
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params



96
97
98
# File 'actionmailer/lib/action_mailer/preview.rb', line 96

def params
  @params
end

Class Method Details

.allObject

Returns all mailer preview classes.



104
105
106
107
# File 'actionmailer/lib/action_mailer/preview.rb', line 104

def all
  load_previews if descendants.empty?
  descendants
end

.call(email, params = {}) ⇒ 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.



112
113
114
115
116
117
# File 'actionmailer/lib/action_mailer/preview.rb', line 112

def call(email, params = {})
  preview = new(params)
  message = preview.public_send(email)
  inform_preview_interceptors(message)
  message
end

.email_exists?(email) ⇒ Boolean

Returns true if the email exists.

Returns:

  • (Boolean)


125
126
127
# File 'actionmailer/lib/action_mailer/preview.rb', line 125

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

.emailsObject

Returns all of the available email previews.



120
121
122
# File 'actionmailer/lib/action_mailer/preview.rb', line 120

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

.exists?(preview) ⇒ Boolean

Returns true if the preview exists.

Returns:

  • (Boolean)


130
131
132
# File 'actionmailer/lib/action_mailer/preview.rb', line 130

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

.find(preview) ⇒ Object

Find a mailer preview by its underscored class name.



135
136
137
# File 'actionmailer/lib/action_mailer/preview.rb', line 135

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

.preview_nameObject

Returns the underscored name of the mailer preview without the suffix.



140
141
142
# File 'actionmailer/lib/action_mailer/preview.rb', line 140

def preview_name
  name.delete_suffix("Preview").underscore
end