Class: Berta::Notification
- Inherits:
-
Object
- Object
- Berta::Notification
- Defined in:
- lib/berta/notification.rb
Overview
Class that encapsulates mailing functionality
Instance Attribute Summary collapse
-
#email ⇒ Object
Returns the value of attribute email.
-
#name ⇒ Object
Returns the value of attribute name.
-
#template ⇒ Object
Returns the value of attribute template.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(name, email, type) ⇒ Notification
constructor
A new instance of Notification.
- #notify(vms) ⇒ Object
- #vms_hash(vms) ⇒ Object
Constructor Details
#initialize(name, email, type) ⇒ Notification
Returns a new instance of Notification.
10 11 12 13 14 15 16 17 |
# 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 |
Instance Attribute Details
#email ⇒ Object
Returns the value of attribute email.
8 9 10 |
# File 'lib/berta/notification.rb', line 8 def email @email end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/berta/notification.rb', line 8 def name @name end |
#template ⇒ Object
Returns the value of attribute template.
8 9 10 |
# File 'lib/berta/notification.rb', line 8 def template @template end |
#type ⇒ Object
Returns the value of attribute type.
8 9 10 |
# File 'lib/berta/notification.rb', line 8 def type @type end |
Instance Method Details
#notify(vms) ⇒ Object
19 20 21 22 23 24 |
# 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) ⇒ Object
26 27 28 29 30 31 32 |
# 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 |