Sha256: cfb9c02e0a38b1ae19b23fd9e7f2b1d4732757c594bcfb5d928cb6428e7ab53b

Contents?: true

Size: 836 Bytes

Versions: 5

Compression:

Stored size: 836 Bytes

Contents

module Maily
  class Mailer
    cattr_accessor :collection
    attr_accessor :name, :emails

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

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

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

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

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

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
maily-0.6.3 lib/maily/mailer.rb
maily-0.6.2 lib/maily/mailer.rb
maily-0.6.1 lib/maily/mailer.rb
maily-0.6.0 lib/maily/mailer.rb
maily-0.5.0 lib/maily/mailer.rb