Class: Maily::Mailer

Inherits:
Object
  • Object
show all
Defined in:
lib/maily/mailer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, methods) ⇒ Mailer



6
7
8
9
10
11
# File 'lib/maily/mailer.rb', line 6

def initialize(name, methods)
  self.collection ||= []
  self.name       = name
  self.emails     = self.class.build_emails(methods, name)
  self.collection << self
end

Instance Attribute Details

#emailsObject

Returns the value of attribute emails.



4
5
6
# File 'lib/maily/mailer.rb', line 4

def emails
  @emails
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/maily/mailer.rb', line 4

def name
  @name
end

Class Method Details

.allObject



13
14
15
16
# File 'lib/maily/mailer.rb', line 13

def self.all
  Maily.load_emails_and_hooks if collection.nil?
  collection
end

.build_emails(methods, mailer) ⇒ Object



22
23
24
25
26
# File 'lib/maily/mailer.rb', line 22

def self.build_emails(methods, mailer)
  methods.map do |email|
    Maily::Email.new(email, mailer)
  end
end

.find(mailer_name) ⇒ Object



18
19
20
# File 'lib/maily/mailer.rb', line 18

def self.find(mailer_name)
  all.find { |mailer| mailer.name == mailer_name }
end

Instance Method Details

#find_email(email_name) ⇒ Object



33
34
35
# File 'lib/maily/mailer.rb', line 33

def find_email(email_name)
  emails.find { |email| email.name == email_name.to_s }
end

#register_hook(email_name, *args) ⇒ Object



28
29
30
31
# File 'lib/maily/mailer.rb', line 28

def register_hook(email_name, *args)
  email = find_email(email_name)
  email.register_hook(args)
end