class GitAgent::Notification
Attributes
config[RW]
diff[R]
homepage[R]
title[R]
Public Class Methods
config=(config)
click to toggle source
# File lib/git_agent/notification.rb, line 9 def config=(config) @config = config Mail.defaults do delivery_method :smtp, address: 'smtp.gmail.com', port: 587, authentication: 'plain', user_name: config[:sender_username], password: config[:sender_password] end end
new(title, homepage = nil, diff = {})
click to toggle source
# File lib/git_agent/notification.rb, line 25 def initialize(title, homepage = nil, diff = {}) assert_config! @title = title @diff = diff @homepage = homepage end
Public Instance Methods
send!()
click to toggle source
# File lib/git_agent/notification.rb, line 33 def send! mail = Mail.new mail.from = config[:sender_username] mail.to = config[:recipient_username] mail.subject = title mail.body = construct_body mail.content_type = 'text/html; charset=UTF-8' mail.deliver! end
Private Instance Methods
assert_config!()
click to toggle source
# File lib/git_agent/notification.rb, line 61 def assert_config! return if Mail.delivery_method.instance_of?(Mail::TestMailer) if !config.key?(:sender_username) || !config.key?(:sender_password) || !config.key?(:recipient_username) raise ArgumentError, ':sender_username, :sender_password and :recipient_username must be defined.' end end
config()
click to toggle source
# File lib/git_agent/notification.rb, line 69 def config self.class.config end
construct_body()
click to toggle source
# File lib/git_agent/notification.rb, line 46 def construct_body str = '' diff.each do |key, values| next if values.empty? str += "<strong>#{key.capitalize}</strong><br/><ul>" values.each { |value| str += "<li>#{value}</li>" } str += "</ul><br/>" end str = "<a href='#{homepage}'>#{homepage}</a><br/>#{str}" if homepage str end