Sha256: e08e5e934a63821d8eb1a8e693f4a2ae959f491fe2a05b01874a52a614596b23

Contents?: true

Size: 829 Bytes

Versions: 1

Compression:

Stored size: 829 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.build_emails 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

1 entries across 1 versions & 1 rubygems

Version Path
maily-0.1.0 lib/maily/mailer.rb