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 CHANGED
@@ -1 +1 @@
1
- 0.1.13
1
+ 0.1.14
data/deputy.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{deputy}
8
- s.version = "0.1.13"
8
+ s.version = "0.1.14"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Michael Grosser"]
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 "#{self.class.to_s.split('::')[1..-1]}.#{key}", value
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.option(:username).should == 'root'
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.option(:foo).should == nil
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.option(:foo).should == nil
65
+ ErrorPlugin.new.send(:option, :foo).should == nil
66
66
  end
67
67
 
68
68
  it "does not overwrite others" do
69
- FooPlugin.new.option(:username).should == 'other'
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.report(:x => 1)
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.report(:x => 1, 'y' => 2)
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
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 13
9
- version: 0.1.13
8
+ - 14
9
+ version: 0.1.14
10
10
  platform: ruby
11
11
  authors:
12
12
  - Michael Grosser