123456789_123456789_123456789_123456789_123456789_

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

::ActiveSupport::DescendantsTracker - Extended

descendants

See additional method definition at line 109.

subclasses

Instance Attribute Summary

Constructor Details

.new(params = {}) ⇒ Preview

[ GitHub ]

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

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

Class Method Details

.all

Returns all mailer preview classes.

[ GitHub ]

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

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.

[ GitHub ]

  
# 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.

[ GitHub ]

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

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

.emails

Returns all of the available email previews.

[ GitHub ]

  
# 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.

[ GitHub ]

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

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

.find(preview)

Find a mailer preview by its underscored class name.

[ GitHub ]

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

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

.preview_name

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

[ GitHub ]

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

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

Instance Attribute Details

#params (readonly)

[ GitHub ]

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

attr_reader :params