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



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

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

#find_email(email_name, version = nil) ⇒ Object



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

def find_email(email_name, version = nil)
  key = Maily::Email.name_with_version(email_name, version)
  emails[key]
end

#hide_email(*email_names) ⇒ Object



49
50
51
52
53
54
# File 'lib/maily/mailer.rb', line 49

def hide_email(*email_names)
  email_names.each do |email_name|
     = Maily::Email.name_with_version(email_name.to_s)
    emails.delete()
  end
end

#register_hook(email_name, *args) ⇒ Object



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

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

#total_emailsObject



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

def total_emails
  emails.size
end