uncouple 0.1.3 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: deab97431c62e5ef08f4c099ad2ac6d3c1b2950f
4
- data.tar.gz: 7205fba6acf8f06d193ec5f6f1149ba4aa8b0bc7
3
+ metadata.gz: c097b94c4c7b8cc0b215c79da0cfca98c3329e73
4
+ data.tar.gz: 844858678dc1949ec6fd8437390759e98d95547a
5
5
  SHA512:
6
- metadata.gz: f009497230256ca2c63ae05dcd4dfc20b4880965af8bb29204a222002c8438253fbf58a04fc8852c512f5eb638d71097eb95b4e061bac4c4e8555c38855cc446
7
- data.tar.gz: 153b886ece82091269883384ad5f0b30aac3a5d7d322ef38c4796cfa30b8ab764bd75b75242cc2c158d284534c026d68c511678c9c24e5fa596cfb19db7a111f
6
+ metadata.gz: edb4530e96ca6af7e5a514719b2a10ca86a8e19b41836af7ed99defb33b2bbdc1da1766e0448e30b10fd1181579ad7562a4eb325222dfee441a9a0241bd13bc8
7
+ data.tar.gz: dfb4c35ab9ce0e2284dc9582ec7ca81ef8d0ca64b577b748a379233d317836cd4f7545d86b9d000b57598d3836597929a57970ab1dd13f437c54b6b94d9c0443
data/README.md CHANGED
@@ -119,6 +119,19 @@ class Metric::CreateAction < Uncouple::Action
119
119
  end
120
120
  ```
121
121
 
122
+ ## Instrumentation through ActiveSupport::Notifications
123
+
124
+ Version 0.2.0 adds support for instrumentation on `perform` and `authorize!` using ActiveSupport::Notifications. Subscribe to notifications using an initializer, and do whatever you like with the data.
125
+
126
+ ```rb
127
+ # config/initializers/notifications.rb
128
+ ActiveSupport::Notifications.subscribe /.*(Action)#(perform|authorize!)/ do |*args|
129
+ event = ActiveSupport::Notifications::Event.new(*args)
130
+ Rails.logger.info "#{event.name} completed in #{event.duration}ms"
131
+ end
132
+
133
+ #=> Metric::IndexAction#perform completed in 8.253ms
134
+ ```
122
135
 
123
136
  ## Development
124
137
 
@@ -0,0 +1,32 @@
1
+ module Uncouple
2
+ class Action
3
+ module Instrumentation
4
+
5
+ def method_added(method)
6
+ case method
7
+ when :perform, :authorize!
8
+ alias_with_instrumentation(method)
9
+ end
10
+ end
11
+
12
+ def alias_with_instrumentation(method)
13
+
14
+ method_without_instrumentation = "#{method}_without_instrumentation".to_sym
15
+ method_with_instrumentation = "#{method}_with_instrumentation".to_sym
16
+
17
+ return if instance_methods.include?(method_with_instrumentation)
18
+
19
+ define_method method_with_instrumentation do
20
+ ActiveSupport::Notifications.instrument "#{self.class.to_s}##{method}", params do
21
+ send(method_without_instrumentation)
22
+ end
23
+ end
24
+
25
+ alias_method method_without_instrumentation, method
26
+ alias_method method, method_with_instrumentation
27
+
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -1,11 +1,8 @@
1
1
  class Uncouple::Railtie < Rails::Railtie
2
2
 
3
3
  initializer "uncouple.configure_rails_initialization" do
4
-
5
- end
6
-
7
- rake_tasks do
8
-
4
+ require "uncouple/action/instrumentation"
5
+ Uncouple::Action.send(:extend, Uncouple::Action::Instrumentation)
9
6
  end
10
7
 
11
8
  generators do
@@ -1,3 +1,3 @@
1
1
  module Uncouple
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uncouple
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Spencer Steffen
@@ -86,6 +86,7 @@ files:
86
86
  - lib/uncouple.rb
87
87
  - lib/uncouple/action.rb
88
88
  - lib/uncouple/action/authorization.rb
89
+ - lib/uncouple/action/instrumentation.rb
89
90
  - lib/uncouple/action_performer.rb
90
91
  - lib/uncouple/rails.rb
91
92
  - lib/uncouple/rails/generators/action_generator.rb