rorvswild 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a59fa9bea7794855a7efa8ba8421e6d9aa5cfd07
4
- data.tar.gz: 2989fc278d1ad9c9ef1a3c308763154ee05b349e
3
+ metadata.gz: 5d51045f4d30998e878c0a5c3db82c8a519c6e41
4
+ data.tar.gz: 53eb0bc8ffe92a7b53e9500af26b351f112edb65
5
5
  SHA512:
6
- metadata.gz: 0510261d172670aa8a3b4e9ec9536a5a84b010464560e4d2f268d6a43b3f1d2c86fa80c9e302da2f8999dec748007fbef31397a151113805e4c947d3371bcd4f
7
- data.tar.gz: 3429bf64bc6895e0aff2258d3fa621d1ccd46c9cbc483d6fc15df67f5b68058177d983707662df1e629c9f44d53dec6770fb3305279fc8daa5f787c78b6039ff
6
+ metadata.gz: 78f0092c6e641139b0c75cbc4895be8ab0d5011292a309cdb871f3ed7a359a385d1766679e49342d09b93ef9cbca86b41a63b1de79312509dd321c5278f277c8
7
+ data.tar.gz: c3c9f93f7bd26a1c8cee07946cc9a74a4c1dfa7a2a3f44449b90fee264ca278a7c56c89d7bda27f42213aea1873437042d9dc0ea4fb2a0003fd1d266054c5230
@@ -1,3 +1,3 @@
1
- class Rorvswild
2
- VERSION = "0.0.7"
1
+ module RorVsWild
2
+ VERSION = "0.0.8".freeze
3
3
  end
data/lib/rorvswild.rb CHANGED
@@ -18,6 +18,14 @@ module RorVsWild
18
18
  default_client ? default_client.measure_job(code) : eval(code)
19
19
  end
20
20
 
21
+ def self.measure_code(code)
22
+ default_client ? default_client.measure_code(code) : eval(code)
23
+ end
24
+
25
+ def self.measure_block(name, &block)
26
+ default_client ? default_client.measure_block(name , &block) : block.call
27
+ end
28
+
21
29
  class Client
22
30
  def self.default_config
23
31
  {
@@ -48,6 +56,8 @@ module RorVsWild
48
56
 
49
57
  client = self
50
58
  ActionController::Base.rescue_from(StandardError) { |exception| client.after_exception(exception, self) }
59
+
60
+ Delayed::Worker.lifecycle.around(:invoke_job, &method(:around_delayed_job)) if defined?(Delayed::Worker)
51
61
  end
52
62
 
53
63
  def before_http_request(name, start, finish, id, payload)
@@ -107,12 +117,25 @@ module RorVsWild
107
117
  raise exception
108
118
  end
109
119
 
120
+ def around_delayed_job(job, &block)
121
+ measure_block(job.name) { block.call(job) }
122
+ end
123
+
110
124
  def measure_job(code)
125
+ warn "WARNING: RorVsWild.measure_job is deprecated. Use RorVsWild.measure_code instead."
126
+ measure_block(code) { eval(code) }
127
+ end
128
+
129
+ def measure_code(code)
130
+ measure_block(code) { eval(code) }
131
+ end
132
+
133
+ def measure_block(name, &block)
111
134
  @queries = []
112
- @job = {name: code}
135
+ @job = {name: name}
113
136
  started_at = Time.now
114
137
  cpu_time_offset = cpu_time
115
- eval(code)
138
+ block.call
116
139
  rescue => exception
117
140
  file, line = exception.backtrace.first.split(":")
118
141
  job[:error] = {
data/rorvswild.gemspec CHANGED
@@ -5,11 +5,11 @@ require 'rorvswild/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "rorvswild"
8
- spec.version = Rorvswild::VERSION
8
+ spec.version = RorVsWild::VERSION
9
9
  spec.authors = ["Alexis Bernard"]
10
10
  spec.email = ["alexis@bernard.io"]
11
11
  spec.summary = "Simple Ruby on Rails application monitoring for hardcore developers with no time to waste."
12
- spec.description = "RorVsWild points bottlenecks of your app and record errors."
12
+ spec.description = "Simple Ruby on Rails application monitoring for hardcore developers with no time to waste."
13
13
  spec.homepage = "http://www.rorvswild.com"
14
14
  spec.license = "MIT"
15
15
 
@@ -10,23 +10,35 @@ require "top_tests"
10
10
  class RorVsWildTest < MiniTest::Unit::TestCase
11
11
  include TopTests
12
12
 
13
- def test_measure_job
13
+ def test_measure_code
14
14
  client.expects(:post_job)
15
- assert_equal(2, client.measure_job("1 + 1"))
15
+ assert_equal(2, client.measure_code("1 + 1"))
16
16
  assert_equal("1 + 1", client.send(:job)[:name])
17
17
  assert(client.send(:job)[:runtime] > 0)
18
18
  assert_equal(0, client.send(:job)[:cpu_runtime])
19
19
  end
20
20
 
21
- def test_measure_job_when_raising
21
+ def test_measure_code_when_raising
22
22
  client.expects(:post_job)
23
- assert_raises(RuntimeError) { client.measure_job("raise 'error'") }
23
+ assert_raises(RuntimeError) { client.measure_code("raise 'error'") }
24
24
  assert_equal(("raise 'error'"), client.send(:job)[:name])
25
25
  assert(client.send(:job)[:cpu_runtime])
26
26
  assert(client.send(:job)[:runtime])
27
27
  assert(client.send(:job)[:error])
28
28
  end
29
29
 
30
+ def test_measure_code_when_no_client
31
+ RorVsWild.register_default_client(nil)
32
+ RorVsWild::Client.any_instance.expects(:post_job).never
33
+ assert_equal(2, RorVsWild.measure_code("1+1"))
34
+ end
35
+
36
+ def test_measure_block_when_no_client
37
+ RorVsWild.register_default_client(nil)
38
+ RorVsWild::Client.any_instance.expects(:post_job).never
39
+ assert_equal(2, RorVsWild.measure_block("1+1") { 1+1 })
40
+ end
41
+
30
42
  private
31
43
 
32
44
  def client
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rorvswild
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexis Bernard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-06 00:00:00.000000000 Z
11
+ date: 2015-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -24,7 +24,8 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.6'
27
- description: RorVsWild points bottlenecks of your app and record errors.
27
+ description: Simple Ruby on Rails application monitoring for hardcore developers with
28
+ no time to waste.
28
29
  email:
29
30
  - alexis@bernard.io
30
31
  executables: []