deputy 0.1.0 → 0.1.1

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/Rakefile CHANGED
@@ -1,3 +1,7 @@
1
+ task :default => :spec
2
+ require 'spec/rake/spectask'
3
+ Spec::Rake::SpecTask.new {|t| t.spec_opts = ['--color -b']}
4
+
1
5
  begin
2
6
  require 'jeweler'
3
7
  project_name = 'deputy'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/bin/deputy CHANGED
@@ -10,7 +10,7 @@ OptionParser.new do |opts|
10
10
  Report to the sheriff
11
11
 
12
12
  Usage:
13
- deputy /System.metric/value
13
+ deputy System.metric value
14
14
 
15
15
  Options:
16
16
  BANNER
data/deputy.gemspec ADDED
@@ -0,0 +1,46 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{deputy}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Michael Grosser"]
12
+ s.date = %q{2010-06-01}
13
+ s.default_executable = %q{deputy}
14
+ s.email = %q{mirko@dawanda.com}
15
+ s.executables = ["deputy"]
16
+ s.files = [
17
+ "Rakefile",
18
+ "Readme.md",
19
+ "VERSION",
20
+ "bin/deputy",
21
+ "deputy.gemspec",
22
+ "lib/deputy.rb",
23
+ "spec/deputy_spec.rb",
24
+ "spec/spec_helper.rb"
25
+ ]
26
+ s.homepage = %q{http://github.com/dawanda/deputy}
27
+ s.rdoc_options = ["--charset=UTF-8"]
28
+ s.require_paths = ["lib"]
29
+ s.rubygems_version = %q{1.3.6}
30
+ s.summary = %q{Report to the sheriff}
31
+ s.test_files = [
32
+ "spec/deputy_spec.rb",
33
+ "spec/spec_helper.rb"
34
+ ]
35
+
36
+ if s.respond_to? :specification_version then
37
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
38
+ s.specification_version = 3
39
+
40
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
41
+ else
42
+ end
43
+ else
44
+ end
45
+ end
46
+
data/lib/deputy.rb CHANGED
@@ -1,11 +1,42 @@
1
1
  require 'yaml'
2
2
  require 'open-uri'
3
3
 
4
+ def eval_and_fetch_constants(x)
5
+ old = Module.constants.map{|c| c.to_s}
6
+ eval(x)
7
+ new = (Module.constants.map{|c| c.to_s} - old)
8
+ new.map{|const| const_get(const) }
9
+ end
10
+
11
+ class Scout
12
+ class Plugin
13
+ def report(metrics)
14
+ metrics.each do |key, value|
15
+ send_report "#{self.class}.#{key}", value
16
+ end
17
+ end
18
+ end
19
+
20
+ def self.plugins(code)
21
+ constants = eval_and_fetch_constants(code)
22
+ constants.select{|constant| constant.instance_methods.map{|m| m.to_sym }.include?(:build_report) }
23
+ end
24
+ end
25
+
4
26
  module Deputy
5
27
  VERSION = File.read( File.join(File.dirname(__FILE__),'..','VERSION') ).strip
6
28
 
29
+ def self.run_plugins
30
+ content = get("/plugins.rb")
31
+ Scout.plugins(content).each{|p| p.new.build_report }
32
+ end
33
+
7
34
  def self.send_report(metric, value)
8
- url = "#{sheriff_url}/report/#{metric}/#{value}"
35
+ get "/report/#{metric}/#{value}"
36
+ end
37
+
38
+ def self.get(path)
39
+ url = "#{sheriff_url}#{path}"
9
40
  open(url).read
10
41
  rescue => e
11
42
  e.message << url
@@ -0,0 +1,39 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe Deputy do
4
+ it "has a VERSION" do
5
+ Deputy::VERSION.should =~ /^\d+\.\d+\.\d+$/
6
+ end
7
+
8
+ def klass(name, code='')
9
+ "class #{name} < Scout::Plugin; def build_report; #{code}; end; end"
10
+ end
11
+
12
+ describe Scout do
13
+ it "finds plugins" do
14
+ Scout.plugins(klass('A')).inspect.should == '[A]'
15
+ end
16
+
17
+ it "does not show non-plugins" do
18
+ Scout.plugins(klass('B').sub('build_report','foo')).inspect.should == '[]'
19
+ end
20
+ end
21
+
22
+ describe :run_plugins do
23
+ it "executes all plugins" do
24
+ $notify = 0
25
+ Deputy.stub!(:sheriff_url).and_return 'http://sheri.ff'
26
+ FakeWeb.register_uri(:get, "http://sheri.ff/plugins.rb", :body => klass('C', '$notify=1'))
27
+ Deputy.run_plugins
28
+ $notify.should == 1
29
+ end
30
+ end
31
+
32
+ describe :send_report do
33
+ it "sends a report" do
34
+ Deputy.stub!(:sheriff_url).and_return 'http://sheri.ff'
35
+ FakeWeb.register_uri(:get, "http://sheri.ff/report/Xxx.yyy/123", :body => 'OK')
36
+ Deputy.send_report('Xxx.yyy', '123').should == 'OK'
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,5 @@
1
+ $LOAD_PATH << 'lib'
2
+ require 'deputy'
3
+
4
+ require 'rubygems'
5
+ require 'fakeweb'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Michael Grosser
@@ -31,7 +31,10 @@ files:
31
31
  - Readme.md
32
32
  - VERSION
33
33
  - bin/deputy
34
+ - deputy.gemspec
34
35
  - lib/deputy.rb
36
+ - spec/deputy_spec.rb
37
+ - spec/spec_helper.rb
35
38
  has_rdoc: true
36
39
  homepage: http://github.com/dawanda/deputy
37
40
  licenses: []
@@ -62,5 +65,6 @@ rubygems_version: 1.3.6
62
65
  signing_key:
63
66
  specification_version: 3
64
67
  summary: Report to the sheriff
65
- test_files: []
66
-
68
+ test_files:
69
+ - spec/deputy_spec.rb
70
+ - spec/spec_helper.rb