Class: Berta::UserHandler
- Inherits:
-
Object
- Object
- Berta::UserHandler
- Defined in:
- lib/berta/user_handler.rb
Overview
Class for handeling user methods
Instance Attribute Summary collapse
-
#handle ⇒ Object
readonly
Returns the value of attribute handle.
Instance Method Summary collapse
-
#initialize(user) ⇒ UserHandler
constructor
Initializes UserHandler object.
-
#notify(user_vms, email_template) ⇒ Object
Notifies user about all vms that are in notification interval.
- #send_notification(user_vms, email_template) ⇒ Object
Constructor Details
#initialize(user) ⇒ UserHandler
Initializes UserHandler object
14 15 16 |
# File 'lib/berta/user_handler.rb', line 14 def initialize(user) @handle = user end |
Instance Attribute Details
#handle ⇒ Object (readonly)
Returns the value of attribute handle.
8 9 10 |
# File 'lib/berta/user_handler.rb', line 8 def handle @handle end |
Instance Method Details
#notify(user_vms, email_template) ⇒ Object
Notifies user about all vms that are in notification interval
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/berta/user_handler.rb', line 23 def notify(user_vms, email_template) to_notify = user_vms.keep_if(&:should_notify?) if to_notify.empty? logger.debug "No notifications for user #{handle['NAME']}" return end send_notification(to_notify, email_template) user_vms.each(&:update_notified) rescue ArgumentError, Berta::Errors::Entities::NoUserEmailError => e logger.error e. end |
#send_notification(user_vms, email_template) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/berta/user_handler.rb', line 35 def send_notification(user_vms, email_template) user_email = handle['TEMPLATE/EMAIL'] user_name = handle['NAME'] raise Berta::Errors::Entities::NoUserEmailError, "User: #{user_name} with id: #{handle['ID']} has no email set" \ unless user_email email_text = email_template.render(Hash, user_email: user_email, user_name: user_name, vms: vms_data(user_vms)) logger.info "Sending mail to user: #{user_name} on email: #{user_email}" logger.debug email_text Mail.new(email_text).deliver unless Berta::Settings['dry-run'] end |