def add_notification_method event, recipient_attribute, via
      mail_method = "#{event}_notification_to_#{recipient_attribute}"

      notification = "#{event}_#{recipient_attribute}".to_sym
      unless notifications_declared.include? notification
        notifications_declared << notification
      else
        raise "Notification for event '#{event}' to recipient '#{recipient_attribute}' already declared!"
      end

      # TODO only define notification method if method is present on mailer
      # TODO create task to generate / update mailer with notification settings

      define_method "#{event}" do |*args|
        returned = super *args if defined? super
        # TODO better error message when mailer is not found
        # TODO allow specification of custom mailer
        mailer = "#{self.class.name}Mailer".classify.constantize

        # TODO better error message when mail method is not found
        entity = send recipient_attribute
        mail   = mailer.send mail_method, self, entity

        mail.deliver or returned
      end
    end
def add_notification_method event, recipient_attribute, via
      mail_method = "#{event}_notification_to_#{recipient_attribute}"

      notification = "#{event}_#{recipient_attribute}".to_sym
      unless notifications_declared.include? notification
        notifications_declared << notification
      else
        raise "Notification for event '#{event}' to recipient '#{recipient_attribute}' already declared!"
      end

      # TODO only define notification method if method is present on mailer
      # TODO create task to generate / update mailer with notification settings

      define_method "#{event}" do |*args|
        returned = super *args if defined? super
        # TODO better error message when mailer is not found
        # TODO allow specification of custom mailer
        mailer = "#{self.class.name}Mailer".classify.constantize

        # TODO better error message when mail method is not found
        entity = send recipient_attribute
        mail   = mailer.send mail_method, self, entity

        mail.deliver or returned
      end
    end
TODO use method missing