class Berta::Notification

Class that encapsulates mailing functionality

Attributes

email[RW]
name[RW]
template[RW]
type[RW]

Public Class Methods

new(name, email, type) click to toggle source
# File lib/berta/notification.rb, line 10
def initialize(name, email, type)
  @type = type
  @name = name
  @email = email
  @template = Tilt.new(Berta::Settings['email-template'])
  raise Berta::Errors::Entities::NoEmailError, 'Notification requires email' \
    unless email
end

Public Instance Methods

notify(vms) click to toggle source
# File lib/berta/notification.rb, line 19
def notify(vms)
  text = template.render(Object.new, name: name, email: email, type: type, vms: vms_hash(vms))
  logger.info "Sending mail to entity: #{name} on email: #{email}"
  logger.debug { text }
  Mail.deliver(text) unless Berta::Settings['dry-run']
end
vms_hash(vms) click to toggle source
# File lib/berta/notification.rb, line 26
def vms_hash(vms)
  vms.map do |vm|
    { id: vm.handle['ID'],
      name: vm.handle['NAME'],
      expiration: vm.default_expiration.time.to_i }
  end
end