Class: Maily::Mailer
- Inherits:
-
Object
- Object
- Maily::Mailer
- Defined in:
- lib/maily/mailer.rb
Instance Attribute Summary collapse
-
#emails ⇒ Object
Returns the value of attribute emails.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #find_email(email_name) ⇒ Object
-
#initialize(name, methods) ⇒ Mailer
constructor
A new instance of Mailer.
- #register_hook(email_name, *args) ⇒ Object
Constructor Details
#initialize(name, methods) ⇒ Mailer
Returns a new instance of Mailer.
7 8 9 10 11 12 |
# File 'lib/maily/mailer.rb', line 7 def initialize(name, methods) self.collection ||= [] self.name = name self.emails = self.class.build_emails(methods, name) self.collection << self end |
Instance Attribute Details
#emails ⇒ Object
Returns the value of attribute emails.
5 6 7 |
# File 'lib/maily/mailer.rb', line 5 def emails @emails end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/maily/mailer.rb', line 5 def name @name end |
Class Method Details
.all ⇒ Object
14 15 16 17 |
# File 'lib/maily/mailer.rb', line 14 def self.all Maily.load_emails_and_hooks if collection.nil? collection end |
.build_emails(methods, mailer) ⇒ Object
23 24 25 26 27 |
# File 'lib/maily/mailer.rb', line 23 def self.build_emails(methods, mailer) methods.map do |email| Maily::Email.new(email, mailer) end end |
.find(mailer_name) ⇒ Object
19 20 21 |
# File 'lib/maily/mailer.rb', line 19 def self.find(mailer_name) all.find { |mailer| mailer.name == mailer_name } end |
Instance Method Details
#find_email(email_name) ⇒ Object
34 35 36 |
# File 'lib/maily/mailer.rb', line 34 def find_email(email_name) emails.find { |email| email.name == email_name.to_s } end |
#register_hook(email_name, *args) ⇒ Object
29 30 31 32 |
# File 'lib/maily/mailer.rb', line 29 def register_hook(email_name, *args) email = find_email(email_name) email.register_hook(args) end |