instrumentable 0.0.3 → 0.0.4

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.
@@ -26,9 +26,13 @@ module Instrumentable
26
26
 
27
27
  # Redefine method_to_instrument to call inside the Notification
28
28
  define_method(method_to_instrument) do |*args, &block|
29
- callable_payload = payload.inject({}) do |result, element|
30
- value = (__send__(element.last) if respond_to?(element.last)) || element.last
31
- result.tap { |r| r[element.first] = value }
29
+ callable_payload = payload.inject({}) do |result, (payload_key, payload_value)|
30
+ value = if respond_to?(payload_value)
31
+ __send__ payload_value
32
+ else
33
+ payload_value
34
+ end
35
+ result.tap { |r| r[payload_key] = value }
32
36
  end
33
37
  ActiveSupport::Notifications.instrument event_name, callable_payload do
34
38
  __send__(instrument_method, *args, &block)
@@ -1,3 +1,3 @@
1
1
  module Instrumentable
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -4,8 +4,10 @@ require_relative "../lib/instrumentable"
4
4
  class FakeModel
5
5
  include Instrumentable
6
6
  def simple_event; end
7
+ def false_event; end
7
8
  def payload_event; end
8
9
  instrument_for :simple_event, 'event.name', :my_payload => :id
10
+ instrument_for :false_event, 'event.name', :my_payload => :valid
9
11
  instrument_for :payload_event, 'payload.name', :my_payload => 'megaman'
10
12
  end
11
13
 
@@ -14,7 +16,7 @@ describe Instrumentable do
14
16
  it "must instrument simple_event" do
15
17
  fm = FakeModel.new
16
18
  def fm.id; 1; end
17
- expected = ['event.name-1']
19
+ expected = ["event.name-#{fm.id}"]
18
20
  events = []
19
21
 
20
22
  callback = lambda { |*_| events << "#{_.first}-#{_.last[:my_payload]}" }
@@ -25,6 +27,20 @@ describe Instrumentable do
25
27
  events.must_equal expected
26
28
  end
27
29
 
30
+ it "must work with callable payload that returns false" do
31
+ fm = FakeModel.new
32
+ def fm.valid; false; end
33
+ expected = ["event.name-#{fm.valid}"]
34
+ events = []
35
+
36
+ callback = lambda { |*_| events << "#{_.first}-#{_.last[:my_payload]}" }
37
+ ActiveSupport::Notifications.subscribed(callback, 'event.name') do
38
+ fm.false_event
39
+ ActiveSupport::Notifications.instrument('other.event')
40
+ end
41
+ events.must_equal expected
42
+ end
43
+
28
44
  it "must handle non-callable payloads" do
29
45
  fm = FakeModel.new
30
46
  expected = ['payload.name-megaman']
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: instrumentable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
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: 2012-12-07 00:00:00.000000000 Z
12
+ date: 2012-12-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport