Class: Blertr::Control
- Inherits:
-
Object
- Object
- Blertr::Control
- Defined in:
- lib/blertr/control.rb
Class Method Summary collapse
-
.alert(command_name, command_time) ⇒ Object
Sends out alert from each notifier if time passed is long enough.
- .change_time(name, time_string) ⇒ Object
- .is_notifier?(name) ⇒ Boolean
- .notifier_with_name(name) ⇒ Object
- .notifiers ⇒ Object
Class Method Details
.alert(command_name, command_time) ⇒ Object
Sends out alert from each notifier if time passed is long enough
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/blertr/control.rb', line 13 def self.alert command_name, command_time # trap interrupt so as to not output # error messages if execution is interrupted interrupted = false trap("INT") {interrupted = true} blacklist = Blacklist.new if !blacklist.blacklisted?(command_name) = Message.new(command_name, command_time) notifiers.each do |notifier| # check if interrupted first and exit # as soon as possible if interrupted exit end if notifier.will_alert?(.command, .seconds) fork do begin notifier.alert rescue puts "problem with #{notifier.name} alert" end #begin exit end #fork end #will_alert? end #each end #!blacklisted? end |
.change_time(name, time_string) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/blertr/control.rb', line 68 def self.change_time name, time_string time_seconds = TimeParser::to_seconds time_string if time_seconds.nil? puts "ERROR: not valid time: #{time_string}" else notifier = notifier_with_name name if notifier puts "setting #{name} to alert after #{time_seconds} seconds" notifier.set_time time_seconds end end end |
.is_notifier?(name) ⇒ Boolean
64 65 66 |
# File 'lib/blertr/control.rb', line 64 def self.is_notifier? name notifier_with_name(name) != nil end |
.notifier_with_name(name) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/blertr/control.rb', line 52 def self.notifier_with_name name notifiers.each do |notifier| if name == notifier.name return notifier end if notifier.names.include? name return notifier end end nil end |
.notifiers ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/blertr/control.rb', line 43 def self.notifiers noters = [] noters << MailNotifier.new noters << GrowlNotifier.new noters << TwitterNotifier.new noters << NotifySendNotifier.new noters end |