lib/ustate/emailer.rb in ustate-client-0.0.3 vs lib/ustate/emailer.rb in ustate-client-0.0.4

- old
+ new

@@ -1,7 +1,10 @@ module UState class Emailer + # Sends emails when the index receives state transitions matching specific + # queries. + require 'net/smtp' attr_accessor :from attr_accessor :host attr_accessor :name @@ -30,11 +33,11 @@ # Send an email to address about state. def email(address, s) raise ArgumentError, "no from address" unless @from # Subject - subject = "#{s.host} #{s.service} #{s.state}" + subject = "#{s.host} #{s.service}" if s.once subject << " transient " else subject << " is " end @@ -57,14 +60,13 @@ end end # Dispatch emails to each address which is interested in this state def receive(*states) - state = states.last Thread.new do @tell.each do |address, q| - if q === state - email address, state + if states.any? { |state| p state; q === state } + email address, states.last end end end end