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) ⇒ Mailer

Returns a new instance of Mailer.



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

def initialize(name)
  self.name   = name
  self.klass  = name.camelize.constantize
  self.emails = {}

  parse_emails

  self.class.collection ||= {}
  self.class.collection[name] = 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

#klassObject

Returns the value of attribute klass.



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

def klass
  @klass
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



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

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

.find(mailer_name) ⇒ Object



26
27
28
# File 'lib/maily/mailer.rb', line 26

def self.find(mailer_name)
  all[mailer_name]
end

.listObject



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

def self.list
  all.values.sort_by(&:name)
end

Instance Method Details

#emails_listObject



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

def emails_list
  emails.values.sort_by(&:name)
end

#find_email(email_name) ⇒ Object



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

def find_email(email_name)
  emails[email_name.to_s]
end

#hide_email(*email_names) ⇒ Object



47
48
49
50
51
# File 'lib/maily/mailer.rb', line 47

def hide_email(*email_names)
  email_names.each do |email_name|
    emails.delete(email_name.to_s)
  end
end

#register_hook(email_name, *args) ⇒ Object



42
43
44
45
# File 'lib/maily/mailer.rb', line 42

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

#total_emailsObject



38
39
40
# File 'lib/maily/mailer.rb', line 38

def total_emails
  emails.size
end