as-notifications 0.2.0 → 1.0.0
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/MIT-LICENSE +27 -1
- data/README.md +30 -0
- data/lib/as/backports/define_singleton_method.rb +12 -0
- data/lib/as/backports/public_send.rb +16 -0
- data/lib/as/notifications.rb +22 -1
- data/lib/as/notifications/instrumenter.rb +2 -2
- data/lib/as/per_thread_registry.rb +57 -0
- metadata +9 -5
data/MIT-LICENSE
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
==> rails license (https://github.com/rails/rails)
|
2
|
+
|
1
3
|
Copyright (c) 2005-2013 David Heinemeier Hansson
|
2
4
|
|
3
5
|
Permission is hereby granted, free of charge, to any person obtaining
|
@@ -17,4 +19,28 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
19
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
20
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
21
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
24
|
+
|
25
|
+
==> backports license (https://github.com/marcandre/backports)
|
26
|
+
|
27
|
+
Copyright (c) 2009 Marc-Andre Lafortune
|
28
|
+
|
29
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
30
|
+
a copy of this software and associated documentation files (the
|
31
|
+
"Software"), to deal in the Software without restriction, including
|
32
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
33
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
34
|
+
permit persons to whom the Software is furnished to do so, subject to
|
35
|
+
the following conditions:
|
36
|
+
|
37
|
+
The above copyright notice and this permission notice shall be
|
38
|
+
included in all copies or substantial portions of the Software.
|
39
|
+
|
40
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
41
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
42
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
43
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
44
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
45
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
46
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
AS::Notification -- Provides an instrumentation API for Ruby
|
2
|
+
------------------------------------------------------------
|
3
|
+
|
4
|
+
AS::Notification is an extraction of ActiveSupport::Notifications from
|
5
|
+
[Rails](https://github.com/rails/rails/tree/master/activesupport).
|
6
|
+
|
7
|
+
**It will track activesupport 4.x once that's released.**
|
8
|
+
|
9
|
+
[](https://travis-ci.org/bernd/as-notifications)
|
10
|
+
|
11
|
+
* [API documentation](http://rubydoc.info/github/bernd/as-notifications/master/AS/Notifications)
|
12
|
+
* [ChangeLog](CHANGELOG.md)
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
$ gem install as-notifications
|
17
|
+
|
18
|
+
## Changes to ActiveSupport::Notifications
|
19
|
+
|
20
|
+
* Change module name from `ActiveSupport::Notifications` to
|
21
|
+
`AS::Notifications` to avoid conflicts with activesupport
|
22
|
+
* Change `require` calls for `active_support/notifications` to
|
23
|
+
`as/notifications`
|
24
|
+
* Disable loading `load_paths` file in tests
|
25
|
+
* Revert [rails/rails@45448a5](https://github.com/rails/rails/commit/45448a5)
|
26
|
+
changes to avoid `thread_safe` gem dependency
|
27
|
+
* Adjust `test/notifications/instrumenter_test.rb` and `test/abstract_unit.rb`
|
28
|
+
to unbreak the tests on Ruby 1.8.
|
29
|
+
* Include `define_singleton_method` and `public_send` [backports](https://github.com/marcandre/backports)
|
30
|
+
to make `ActiveSupport::PerThreadRegistry` work on Ruby 1.8.
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# From https://github.com/marcandre/backports
|
2
|
+
# backports is released under the terms of the MIT License, see the included
|
3
|
+
# LICENSE file.
|
4
|
+
unless Kernel.method_defined? :define_singleton_method
|
5
|
+
module Kernel
|
6
|
+
def define_singleton_method(*args, &block)
|
7
|
+
class << self
|
8
|
+
self
|
9
|
+
end.send(:define_method, *args, &block)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# From https://github.com/marcandre/backports
|
2
|
+
# backports is released under the terms of the MIT License, see the included
|
3
|
+
# LICENSE file.
|
4
|
+
unless Kernel.method_defined? :public_send
|
5
|
+
module Kernel
|
6
|
+
def public_send(method, *args, &block)
|
7
|
+
if respond_to?(method) && !protected_methods.include?(method.to_s)
|
8
|
+
send(method, *args, &block)
|
9
|
+
else
|
10
|
+
:foo.generate_a_no_method_error_in_preparation_for_method_missing rescue nil
|
11
|
+
# otherwise a NameError might be raised when we call method_missing ourselves
|
12
|
+
method_missing(method.to_sym, *args, &block)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/as/notifications.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'as/notifications/instrumenter'
|
2
2
|
require 'as/notifications/fanout'
|
3
|
+
require 'as/per_thread_registry'
|
3
4
|
|
4
5
|
module AS
|
5
6
|
# = Notifications
|
@@ -177,7 +178,27 @@ module AS
|
|
177
178
|
end
|
178
179
|
|
179
180
|
def instrumenter
|
180
|
-
|
181
|
+
InstrumentationRegistry.instrumenter_for(notifier)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
# This class is a registry which holds all of the +Instrumenter+ objects
|
186
|
+
# in a particular thread local. To access the +Instrumenter+ object for a
|
187
|
+
# particular +notifier+, you can call the following method:
|
188
|
+
#
|
189
|
+
# InstrumentationRegistry.instrumenter_for(notifier)
|
190
|
+
#
|
191
|
+
# The instrumenters for multiple notifiers are held in a single instance of
|
192
|
+
# this class.
|
193
|
+
class InstrumentationRegistry # :nodoc:
|
194
|
+
extend AS::PerThreadRegistry
|
195
|
+
|
196
|
+
def initialize
|
197
|
+
@registry = {}
|
198
|
+
end
|
199
|
+
|
200
|
+
def instrumenter_for(notifier)
|
201
|
+
@registry[notifier] ||= Instrumenter.new(notifier)
|
181
202
|
end
|
182
203
|
end
|
183
204
|
|
@@ -2,7 +2,7 @@ require 'securerandom'
|
|
2
2
|
|
3
3
|
module AS
|
4
4
|
module Notifications
|
5
|
-
#
|
5
|
+
# Instrumenters are stored in a thread local.
|
6
6
|
class Instrumenter
|
7
7
|
attr_reader :id
|
8
8
|
|
@@ -17,7 +17,7 @@ module AS
|
|
17
17
|
def instrument(name, payload={})
|
18
18
|
start name, payload
|
19
19
|
begin
|
20
|
-
yield
|
20
|
+
yield payload
|
21
21
|
rescue Exception => e
|
22
22
|
payload[:exception] = [e.class.name, e.message]
|
23
23
|
raise e
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module AS
|
2
|
+
# This module is used to encapsulate access to thread local variables.
|
3
|
+
#
|
4
|
+
# Instead of polluting the thread locals namespace:
|
5
|
+
#
|
6
|
+
# Thread.current[:connection_handler]
|
7
|
+
#
|
8
|
+
# you define a class that extends this module:
|
9
|
+
#
|
10
|
+
# module ActiveRecord
|
11
|
+
# class RuntimeRegistry
|
12
|
+
# extend AS::PerThreadRegistry
|
13
|
+
#
|
14
|
+
# attr_accessor :connection_handler
|
15
|
+
# end
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# and invoke the declared instance accessors as class methods. So
|
19
|
+
#
|
20
|
+
# ActiveRecord::RuntimeRegistry.connection_handler = connection_handler
|
21
|
+
#
|
22
|
+
# sets a connection handler local to the current thread, and
|
23
|
+
#
|
24
|
+
# ActiveRecord::RuntimeRegistry.connection_handler
|
25
|
+
#
|
26
|
+
# returns a connection handler local to the current thread.
|
27
|
+
#
|
28
|
+
# This feature is accomplished by instantiating the class and storing the
|
29
|
+
# instance as a thread local keyed by the class name. In the example above
|
30
|
+
# a key "ActiveRecord::RuntimeRegistry" is stored in <tt>Thread.current</tt>.
|
31
|
+
# The class methods proxy to said thread local instance.
|
32
|
+
#
|
33
|
+
# If the class has an initializer, it must accept no arguments.
|
34
|
+
module PerThreadRegistry
|
35
|
+
if RUBY_VERSION < '1.9'
|
36
|
+
require 'as/backports/define_singleton_method'
|
37
|
+
require 'as/backports/public_send'
|
38
|
+
end
|
39
|
+
|
40
|
+
protected
|
41
|
+
|
42
|
+
def method_missing(name, *args, &block) # :nodoc:
|
43
|
+
# Caches the method definition as a singleton method of the receiver.
|
44
|
+
define_singleton_method(name) do |*a, &b|
|
45
|
+
per_thread_registry_instance.public_send(name, *a, &b)
|
46
|
+
end
|
47
|
+
|
48
|
+
send(name, *args, &block)
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def per_thread_registry_instance
|
54
|
+
Thread.current[name] ||= new
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: as-notifications
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-04-27 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Provides an instrumentation API for Ruby. It has been extracted from
|
15
15
|
rails activesupport.
|
@@ -19,7 +19,11 @@ extensions: []
|
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
21
|
- MIT-LICENSE
|
22
|
+
- README.md
|
23
|
+
- lib/as/per_thread_registry.rb
|
22
24
|
- lib/as/notifications.rb
|
25
|
+
- lib/as/backports/define_singleton_method.rb
|
26
|
+
- lib/as/backports/public_send.rb
|
23
27
|
- lib/as/notifications/fanout.rb
|
24
28
|
- lib/as/notifications/instrumenter.rb
|
25
29
|
homepage: https://github.com/bernd/as-notifications
|
@@ -39,7 +43,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
39
43
|
version: '0'
|
40
44
|
segments:
|
41
45
|
- 0
|
42
|
-
hash:
|
46
|
+
hash: 2076711471121766767
|
43
47
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
48
|
none: false
|
45
49
|
requirements:
|
@@ -48,10 +52,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
48
52
|
version: '0'
|
49
53
|
segments:
|
50
54
|
- 0
|
51
|
-
hash:
|
55
|
+
hash: 2076711471121766767
|
52
56
|
requirements: []
|
53
57
|
rubyforge_project:
|
54
|
-
rubygems_version: 1.8.
|
58
|
+
rubygems_version: 1.8.25
|
55
59
|
signing_key:
|
56
60
|
specification_version: 3
|
57
61
|
summary: Provides an instrumentation API for Ruby
|