dboard 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/collector.rb CHANGED
@@ -11,12 +11,17 @@ module Dboard
11
11
  Collector.instance.register_source(key, instance)
12
12
  end
13
13
 
14
+ def self.register_after_update_callback(callback)
15
+ Collector.instance.register_after_update_callback(callback)
16
+ end
17
+
14
18
  def self.start
15
19
  instance.start
16
20
  end
17
21
 
18
22
  def initialize
19
23
  @sources = {}
24
+ @after_update_callback = lambda {}
20
25
  end
21
26
 
22
27
  def start
@@ -38,8 +43,12 @@ module Dboard
38
43
  end
39
44
 
40
45
  def update_source(source, instance)
41
- data = instance.fetch
42
- publish_data(source, data)
46
+ begin
47
+ data = instance.fetch
48
+ publish_data(source, data)
49
+ ensure
50
+ @after_update_callback.call
51
+ end
43
52
  rescue Exception => ex
44
53
  puts "Failed to update #{source}: #{ex.message}"
45
54
  puts ex.backtrace
@@ -49,6 +58,10 @@ module Dboard
49
58
  @sources.merge!({ key => instance })
50
59
  end
51
60
 
61
+ def register_after_update_callback(callback)
62
+ @after_update_callback = callback
63
+ end
64
+
52
65
  def publish_data(source, data)
53
66
  Publisher.publish(source, data)
54
67
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dboard
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -13,6 +13,20 @@ describe Dboard::Collector, "register_source" do
13
13
  Dboard::Collector.instance.sources.should == { :new_relic => new_relic }
14
14
  end
15
15
 
16
+ it "can register an after update callback" do
17
+ new_relic = mock
18
+ new_relic.stub!(:fetch).and_return({ :db => "100%" })
19
+ callback = mock
20
+ Dboard::Collector.instance.register_after_update_callback callback
21
+
22
+ callback.should_receive(:call)
23
+ Dboard::Publisher.stub!(:publish)
24
+ Dboard::Collector.instance.update_source(:new_relic, new_relic)
25
+
26
+ # since it is a singleton, and this callbacks leaks into the other tests
27
+ Dboard::Collector.instance.register_after_update_callback(lambda {})
28
+ end
29
+
16
30
  end
17
31
 
18
32
  describe Dboard::Collector, "update_source" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dboard
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Joakim Kolsj\xC3\xB6"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-02-14 00:00:00 +01:00
18
+ date: 2012-08-16 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency