deputy 0.1.13 → 0.1.14
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/deputy.gemspec +1 -1
- data/lib/deputy.rb +27 -1
- data/spec/deputy_spec.rb +32 -8
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.14
|
data/deputy.gemspec
CHANGED
data/lib/deputy.rb
CHANGED
@@ -13,9 +13,11 @@ class Scout
|
|
13
13
|
class Plugin
|
14
14
|
OPTIONS = {}.to_yaml
|
15
15
|
|
16
|
+
protected
|
17
|
+
|
16
18
|
def report(metrics)
|
17
19
|
metrics.each do |key, value|
|
18
|
-
Deputy.send_report "#{
|
20
|
+
Deputy.send_report "#{clean_class_name}.#{key}", value
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
@@ -27,6 +29,30 @@ class Scout
|
|
27
29
|
report :alert => args.map{|a| a.inspect}.join(', ')
|
28
30
|
end
|
29
31
|
|
32
|
+
def memory(key)
|
33
|
+
complete_memory[key]
|
34
|
+
end
|
35
|
+
|
36
|
+
def remember(data)
|
37
|
+
all = complete_memory.merge(data)
|
38
|
+
File.open(memory_file, 'w'){|f| f.write all.to_yaml }
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def complete_memory
|
44
|
+
return {} unless File.exist?(memory_file)
|
45
|
+
YAML.load(File.read(memory_file)) || {}
|
46
|
+
end
|
47
|
+
|
48
|
+
def memory_file
|
49
|
+
"/tmp/deputy.memory.#{clean_class_name}.yml"
|
50
|
+
end
|
51
|
+
|
52
|
+
def clean_class_name
|
53
|
+
self.class.to_s.split('::')[1..-1].join('::')
|
54
|
+
end
|
55
|
+
|
30
56
|
# stub options for now...
|
31
57
|
def option(key)
|
32
58
|
(YAML.load(self.class::OPTIONS)[key.to_s]||{})['default']
|
data/spec/deputy_spec.rb
CHANGED
@@ -54,42 +54,66 @@ describe Deputy do
|
|
54
54
|
|
55
55
|
describe :option do
|
56
56
|
it "get default" do
|
57
|
-
OptionsPlugin.new.
|
57
|
+
OptionsPlugin.new.send(:option, :username).should == 'root'
|
58
58
|
end
|
59
59
|
|
60
60
|
it "get nil when no default is there" do
|
61
|
-
OptionsPlugin.new.
|
61
|
+
OptionsPlugin.new.send(:option, :foo).should == nil
|
62
62
|
end
|
63
63
|
|
64
64
|
it "get nil when no OPTIONS are there" do
|
65
|
-
ErrorPlugin.new.
|
65
|
+
ErrorPlugin.new.send(:option, :foo).should == nil
|
66
66
|
end
|
67
67
|
|
68
68
|
it "does not overwrite others" do
|
69
|
-
FooPlugin.new.
|
69
|
+
FooPlugin.new.send(:option, :username).should == 'other'
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
73
|
describe :report do
|
74
74
|
it "sends a report" do
|
75
75
|
Deputy.should_receive(:send_report).with("NestedPlugin.x", 1)
|
76
|
-
FooPlugin::NestedPlugin.new.
|
76
|
+
FooPlugin::NestedPlugin.new.send(:report, :x => 1)
|
77
77
|
end
|
78
78
|
|
79
79
|
it "sends multiple reports" do
|
80
80
|
Deputy.should_receive(:send_report).with("NestedPlugin.x", 1)
|
81
81
|
Deputy.should_receive(:send_report).with("NestedPlugin.y", 2)
|
82
|
-
FooPlugin::NestedPlugin.new.
|
82
|
+
FooPlugin::NestedPlugin.new.send(:report, :x => 1, 'y' => 2)
|
83
83
|
end
|
84
84
|
|
85
85
|
it "sends alerts" do
|
86
86
|
Deputy.should_receive(:send_report).with("NestedPlugin.alert", '1, "2"')
|
87
|
-
FooPlugin::NestedPlugin.new.alert 1, "2"
|
87
|
+
FooPlugin::NestedPlugin.new.send(:alert, 1, "2")
|
88
88
|
end
|
89
89
|
|
90
90
|
it "sends errors" do
|
91
91
|
Deputy.should_receive(:send_report).with("NestedPlugin.error", '1, "2"')
|
92
|
-
FooPlugin::NestedPlugin.new.error 1, "2"
|
92
|
+
FooPlugin::NestedPlugin.new.send(:error, 1, "2")
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe :memory do
|
97
|
+
before do
|
98
|
+
`rm -f #{FooPlugin::NestedPlugin.new.send(:memory_file)}`
|
99
|
+
`rm -f #{FooPlugin.new.send(:memory_file)}`
|
100
|
+
end
|
101
|
+
|
102
|
+
it "remembers" do
|
103
|
+
FooPlugin::NestedPlugin.new.send(:remember, 'foo' => 1)
|
104
|
+
FooPlugin::NestedPlugin.new.send(:memory, 'foo').should == 1
|
105
|
+
end
|
106
|
+
|
107
|
+
it "remembers different stuff" do
|
108
|
+
FooPlugin::NestedPlugin.new.send(:remember, :foo => 1)
|
109
|
+
FooPlugin::NestedPlugin.new.send(:remember, :bar => 1)
|
110
|
+
FooPlugin::NestedPlugin.new.send(:memory, :foo).should == 1
|
111
|
+
FooPlugin::NestedPlugin.new.send(:memory, :bar).should == 1
|
112
|
+
end
|
113
|
+
|
114
|
+
it "is nil for unremembered" do
|
115
|
+
FooPlugin::NestedPlugin.new.send(:memory, :asdsa).should == nil
|
116
|
+
FooPlugin.new.send(:memory, :asdsa).should == nil
|
93
117
|
end
|
94
118
|
end
|
95
119
|
end
|