class Maily::Mailer
Attributes
emails[RW]
klass[RW]
name[RW]
Public Class Methods
all()
click to toggle source
# File lib/maily/mailer.rb, line 17 def self.all Maily.load_emails_and_hooks if collection.nil? collection end
find(mailer_name)
click to toggle source
# File lib/maily/mailer.rb, line 26 def self.find(mailer_name) all[mailer_name] end
list()
click to toggle source
# File lib/maily/mailer.rb, line 22 def self.list all.values.sort_by(&:name) end
new(name)
click to toggle source
# 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
Public Instance Methods
emails_list()
click to toggle source
# File lib/maily/mailer.rb, line 35 def emails_list emails.values.sort_by(&:name) end
find_email(email_name, version = nil)
click to toggle source
# 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)
click to toggle source
# File lib/maily/mailer.rb, line 49 def hide_email(*email_names) email_names.each do |email_name| _email_name = Maily::Email.name_with_version(email_name.to_s) emails.delete(_email_name) end end
register_hook(email_name, *args)
click to toggle source
# 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_emails()
click to toggle source
# File lib/maily/mailer.rb, line 39 def total_emails emails.size end
Private Instance Methods
add_email(email_name, version = nil)
click to toggle source
# File lib/maily/mailer.rb, line 66 def add_email(email_name, version = nil) hide_email(email_name) if version email = Maily::Email.new(email_name.to_s, self) key = Maily::Email.name_with_version(email_name, version) emails[key] = email end
get_version(*args)
click to toggle source
# File lib/maily/mailer.rb, line 73 def get_version(*args) return unless args.last.is_a?(Hash) Maily::Email.formatted_version(args.last[:version]) end
parse_emails()
click to toggle source
# File lib/maily/mailer.rb, line 58 def parse_emails _emails = klass.send(:public_instance_methods, false) _emails.each do |email| add_email(email) end end