graytoad 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
data/graytoad.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{graytoad}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Alexey Palazhchenko"]
@@ -23,8 +23,9 @@ Gem::Specification.new do |s|
23
23
  "Rakefile",
24
24
  "VERSION",
25
25
  "graytoad.gemspec",
26
- "lib/Graytoad.rb",
27
- "test/helper.rb"
26
+ "lib/graytoad.rb",
27
+ "test/helper.rb",
28
+ "test/test_graytoad.rb"
28
29
  ]
29
30
  s.homepage = %q{http://github.com/AlekSi/graytoad}
30
31
  s.rdoc_options = ["--charset=UTF-8"]
@@ -32,8 +33,8 @@ Gem::Specification.new do |s|
32
33
  s.rubygems_version = %q{1.3.7}
33
34
  s.summary = %q{Graylog2 + Hoptoad}
34
35
  s.test_files = [
35
- "test/graytoad.rb",
36
- "test/helper.rb"
36
+ "test/helper.rb",
37
+ "test/test_graytoad.rb"
37
38
  ]
38
39
 
39
40
  if s.respond_to? :specification_version then
data/lib/graytoad.rb ADDED
@@ -0,0 +1,36 @@
1
+ require "gelf"
2
+ require "hoptoad_notifier"
3
+
4
+ class Graytoad
5
+ class << self
6
+ attr_accessor :gelf_host, :gelf_port, :this_host
7
+
8
+ def notify(e, opts={})
9
+ detect_this_host if this_host.nil?
10
+
11
+ if e.is_a?(Hash)
12
+ opts, e = e, nil
13
+ end
14
+
15
+ g = Gelf.new(gelf_host, gelf_port)
16
+ g.host = this_host
17
+
18
+ if e.nil?
19
+ g.short_message, g.full_message = "#{opts[:error_class]}: #{opts[:error_message]}", caller
20
+ opts.each_pair { |key, value| g.add_additional(key, value) }
21
+ HoptoadNotifier.notify(opts)
22
+ else
23
+ g.short_message, g.full_message = e.message, e.backtrace
24
+ HoptoadNotifier.notify(e, opts)
25
+ end
26
+
27
+ g.send
28
+ end
29
+
30
+ private
31
+ def detect_this_host
32
+ require 'socket'
33
+ self.this_host = Socket.gethostname
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,39 @@
1
+ require 'helper'
2
+ require 'socket'
3
+
4
+ HOST = Socket.gethostname
5
+
6
+ class TestGraytoad < Test::Unit::TestCase
7
+ context "with exception" do
8
+ setup do
9
+ @e = RuntimeError.new("Short message")
10
+ Gelf.any_instance.expects(:short_message=)
11
+ Gelf.any_instance.expects(:full_message=)
12
+ Gelf.any_instance.expects(:host=).with(HOST)
13
+ end
14
+
15
+ should "notify with exception" do
16
+ Gelf.any_instance.expects(:send)
17
+
18
+ HoptoadNotifier.expects(:notify).with(@e, {})
19
+
20
+ Graytoad.notify(@e)
21
+ end
22
+
23
+ should "notify with exception and params" do
24
+ Gelf.any_instance.expects(:send)
25
+
26
+ HoptoadNotifier.expects(:notify).with(@e, :user => 'user')
27
+
28
+ Graytoad.notify(@e, :user => 'user')
29
+ end
30
+
31
+ should "notify with params" do
32
+ Gelf.any_instance.expects(:send)
33
+
34
+ HoptoadNotifier.expects(:notify).with(:error_class => @e.class.to_s, :error_message => @e.message.to_s, :other_param => 'Param')
35
+
36
+ Graytoad.notify(:error_class => @e.class.to_s, :error_message => @e.message.to_s, :other_param => 'Param')
37
+ end
38
+ end
39
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graytoad
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alexey Palazhchenko
@@ -99,9 +99,9 @@ files:
99
99
  - Rakefile
100
100
  - VERSION
101
101
  - graytoad.gemspec
102
- - lib/Graytoad.rb
102
+ - lib/graytoad.rb
103
103
  - test/helper.rb
104
- - test/graytoad.rb
104
+ - test/test_graytoad.rb
105
105
  has_rdoc: true
106
106
  homepage: http://github.com/AlekSi/graytoad
107
107
  licenses: []
@@ -137,5 +137,5 @@ signing_key:
137
137
  specification_version: 3
138
138
  summary: Graylog2 + Hoptoad
139
139
  test_files:
140
- - test/graytoad.rb
141
140
  - test/helper.rb
141
+ - test/test_graytoad.rb
data/lib/Graytoad.rb DELETED
@@ -1,24 +0,0 @@
1
- require "gelf"
2
- require "hoptoad_notifier"
3
-
4
- class Graytoad
5
- class << self
6
- attr_accessor :gelf_host, :gelf_port, :this_host
7
-
8
- def notify(e)
9
- detect_this_host if this_host.nil?
10
-
11
- HoptoadNotifier.notify(e)
12
-
13
- g = Gelf.new(gelf_host, gelf_port)
14
- g.short_message, g.full_message, g.host = e.message, e.backtrace, this_host
15
- g.send
16
- end
17
-
18
- private
19
- def detect_this_host
20
- require 'socket'
21
- self.this_host = Socket.gethostname
22
- end
23
- end
24
- end
data/test/graytoad.rb DELETED
@@ -1,19 +0,0 @@
1
- require 'helper'
2
- require 'socket'
3
-
4
- HOST = Socket.gethostname
5
-
6
- class TestGraytoad < Test::Unit::TestCase
7
- should "notify with standard excpetion" do
8
- e = RuntimeError.new("Short message")
9
-
10
- Gelf.any_instance.expects(:short_message=).with(e.message)
11
- Gelf.any_instance.expects(:full_message=).with(e.backtrace)
12
- Gelf.any_instance.expects(:host=).with(HOST)
13
- Gelf.any_instance.expects(:send)
14
-
15
- HoptoadNotifier.expects(:notify).with(e)
16
-
17
- Graytoad.notify(e)
18
- end
19
- end