Class: ActionMailer::Preview
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
|
|
Inherits: | Object |
Defined in: | actionmailer/lib/action_mailer/preview.rb |
Class Method Summary
-
.all
Returns all mailer preview classes.
-
.call(email, params = {})
Returns the mail object for the given email name.
-
.email_exists?(email) ⇒ Boolean
Returns
true
if the email exists. -
.emails
Returns all of the available email previews.
-
.exists?(preview) ⇒ Boolean
Returns
true
if the preview exists. -
.find(preview)
Find a mailer preview by its underscored class name.
- .new(params = {}) ⇒ Preview constructor
-
.preview_name
Returns the underscored name of the mailer preview without the suffix.
- .inform_preview_interceptors(message) private
- .load_previews private
- .preview_paths private
- .show_previews private
::ActiveSupport::DescendantsTracker
- Extended
Instance Attribute Summary
- #params readonly
Constructor Details
.new(params = {}) ⇒ Preview
Class Method Details
.all
Returns all mailer preview classes.
# File 'actionmailer/lib/action_mailer/preview.rb', line 80
def all load_previews if descendants.empty? descendants.sort_by { |mailer| mailer.name.titleize } end
.call(email, params = {})
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.
# File 'actionmailer/lib/action_mailer/preview.rb', line 88
def call(email, params = {}) preview = new(params) = preview.public_send(email) inform_preview_interceptors( ) end
.email_exists?(email) ⇒ Boolean
Returns true
if the email exists.
# File 'actionmailer/lib/action_mailer/preview.rb', line 101
def email_exists?(email) emails.include?(email) end
.emails
Returns all of the available email previews.
# File 'actionmailer/lib/action_mailer/preview.rb', line 96
def emails public_instance_methods(false).map(&:to_s).sort end
.exists?(preview) ⇒ Boolean
Returns true
if the preview exists.
# File 'actionmailer/lib/action_mailer/preview.rb', line 106
def exists?(preview) all.any? { |p| p.preview_name == preview } end
.find(preview)
Find a mailer preview by its underscored class name.
# File 'actionmailer/lib/action_mailer/preview.rb', line 111
def find(preview) all.find { |p| p.preview_name == preview } end
.inform_preview_interceptors(message) (private)
[ GitHub ]# File 'actionmailer/lib/action_mailer/preview.rb', line 135
def inform_preview_interceptors( ) Base.preview_interceptors.each do |interceptor| interceptor.previewing_email( ) end end
.load_previews (private)
[ GitHub ]# File 'actionmailer/lib/action_mailer/preview.rb', line 121
def load_previews preview_paths.each do |preview_path| Dir["#{preview_path}/**/*_preview.rb"].sort.each { |file| require file } end end
.preview_name
Returns the underscored name of the mailer preview without the suffix.
# File 'actionmailer/lib/action_mailer/preview.rb', line 116
def preview_name name.delete_suffix("Preview").underscore end
.preview_paths (private)
[ GitHub ]# File 'actionmailer/lib/action_mailer/preview.rb', line 127
def preview_paths Base.preview_paths end
.show_previews (private)
[ GitHub ]# File 'actionmailer/lib/action_mailer/preview.rb', line 131
def show_previews Base.show_previews end
Instance Attribute Details
#params (readonly)
[ GitHub ]# File 'actionmailer/lib/action_mailer/preview.rb', line 72
attr_reader :params