Class: Spanx::Notifier::Email

Inherits:
Base
  • Object
show all
Defined in:
lib/spanx/notifier/email.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Email

Returns a new instance of Email.



9
10
11
12
13
# File 'lib/spanx/notifier/email.rb', line 9

def initialize(config)
  @config = config[:email]

  configure_email_gateway
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/spanx/notifier/email.rb', line 7

def config
  @config
end

#threadObject (readonly)

Returns the value of attribute thread.



7
8
9
# File 'lib/spanx/notifier/email.rb', line 7

def thread
  @thread
end

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/spanx/notifier/email.rb', line 32

def enabled?
  config && config[:enabled]
end

#publish(blocked_ip) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/spanx/notifier/email.rb', line 15

def publish(blocked_ip)
  return unless enabled?

  @thread = Thread.new do
    Thread.current[:name] = "email notifier"
    Logger.log "sending notification email for #{blocked_ip.identifier}"

    mail = Mail.new
    mail.to = config[:to]
    mail.from = config[:from]
    mail.subject = subject(blocked_ip)
    mail.body = generate_block_ip_message(blocked_ip)

    mail.deliver
  end
end