Class: CampfireChat::Monitor
- Inherits:
-
Object
- Object
- CampfireChat::Monitor
- Includes:
- Singleton
- Defined in:
- lib/campfire_chat/monitor.rb
Instance Attribute Summary collapse
-
#last_run_time ⇒ Object
Returns the value of attribute last_run_time.
Class Method Summary collapse
Instance Method Summary collapse
- #check_client? ⇒ Boolean
- #check_messages ⇒ Object
- #client ⇒ Object
- #notifier ⇒ Object
- #prepare_notification(message) ⇒ Object
- #run ⇒ Object
- #set_last_run_time ⇒ Object
Instance Attribute Details
#last_run_time ⇒ Object
Returns the value of attribute last_run_time.
4 5 6 |
# File 'lib/campfire_chat/monitor.rb', line 4 def last_run_time @last_run_time end |
Class Method Details
.retry_time ⇒ Object
6 7 8 |
# File 'lib/campfire_chat/monitor.rb', line 6 def self.retry_time 30 end |
.run ⇒ Object
14 15 16 |
# File 'lib/campfire_chat/monitor.rb', line 14 def self.run instance.run end |
.sleep_time ⇒ Object
10 11 12 |
# File 'lib/campfire_chat/monitor.rb', line 10 def self.sleep_time retry_time / 2 end |
Instance Method Details
#check_client? ⇒ Boolean
39 40 41 42 |
# File 'lib/campfire_chat/monitor.rb', line 39 def check_client? return true if last_run_time.nil? last_run_time + self.class.retry_time < Time.now end |
#check_messages ⇒ Object
28 29 30 31 32 33 |
# File 'lib/campfire_chat/monitor.rb', line 28 def client..each do || notification = prepare_notification() notifier.push(notification) end end |
#client ⇒ Object
48 49 50 |
# File 'lib/campfire_chat/monitor.rb', line 48 def client @client ||= CampfireChat::Client.new end |
#notifier ⇒ Object
52 53 54 |
# File 'lib/campfire_chat/monitor.rb', line 52 def notifier @notifier ||= CampfireChat::Notifier::Growl.instance end |
#prepare_notification(message) ⇒ Object
44 45 46 |
# File 'lib/campfire_chat/monitor.rb', line 44 def prepare_notification() CampfireChat::Notification.build() end |
#run ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/campfire_chat/monitor.rb', line 18 def run loop do if check_client? set_last_run_time sleep self.class.sleep_time end end end |
#set_last_run_time ⇒ Object
35 36 37 |
# File 'lib/campfire_chat/monitor.rb', line 35 def set_last_run_time self.last_run_time = Time.now end |