active_spy 1.0.0 → 1.1.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 +4 -4
- data/VERSION +1 -1
- data/active_spy.gemspec +3 -3
- data/lib/active_spy/spy/spy_list.rb +26 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c5c53150581386f90a25dccf81f694889d7dfe5
|
4
|
+
data.tar.gz: 8d082156907df01556796dcb8ff30f8d044e5c41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3c5bdf1f6258d88e0aa6bdabd52c37c296a8a51d68e0a6929b5f0d5bc41daac320b353cdfbc6b080687130cbf6cc28b00745d561ce1890549b54dfa341c2875
|
7
|
+
data.tar.gz: b6cedef22c6ca6adbc4ef893a698a8cfa56b8600069599e3c9a0f19ce8930f5a44610762217a70d823e62c6a06b7a73a4a139c0dfeb97b24d8422b3be81d1e3c
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.1.0
|
data/active_spy.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: active_spy 1.
|
5
|
+
# stub: active_spy 1.1.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "active_spy"
|
9
|
-
s.version = "1.
|
9
|
+
s.version = "1.1.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Douglas Camata"]
|
14
|
-
s.date = "2014-07-
|
14
|
+
s.date = "2014-07-18"
|
15
15
|
s.description = " Watch for a method call in any class and run before/after callbacks.\n You can even watch your Rails models for events (like create, update,\n destroy), send these events to a event-runner instance and it redirect these\n events to other apps that are subscrived for them. This gem also provides\n classes that you can use to process the received events too.\n"
|
16
16
|
s.email = "d.camata@gmail.com"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -23,7 +23,7 @@ module ActiveSpy
|
|
23
23
|
instance.send(method, *args, &block)
|
24
24
|
end
|
25
25
|
|
26
|
-
#
|
26
|
+
# Activate all the spies defined in the spy list by patching the methods
|
27
27
|
# in their classes.
|
28
28
|
#
|
29
29
|
def activate
|
@@ -31,7 +31,18 @@ module ActiveSpy
|
|
31
31
|
spied_class = spy['class']
|
32
32
|
spied_method = spy['method']
|
33
33
|
|
34
|
-
patch(spied_class, spied_method)
|
34
|
+
spy['old_method'] = patch(spied_class, spied_method) unless spy['active']
|
35
|
+
spy['active'] = true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Deactivate all the spies defined in the spy list by unpatching the methods
|
40
|
+
# in their classes.
|
41
|
+
#
|
42
|
+
def deactivate
|
43
|
+
@spies.each do |spy|
|
44
|
+
unpatch(spy['class'], spy['method'], spy['old_method'])
|
45
|
+
spy['active'] = nil
|
35
46
|
end
|
36
47
|
end
|
37
48
|
|
@@ -49,6 +60,7 @@ module ActiveSpy
|
|
49
60
|
# {ActiveSpy::Base}.
|
50
61
|
#
|
51
62
|
def patch(klass, method)
|
63
|
+
old_method = nil
|
52
64
|
ActiveSupport::Inflector.constantize(klass).class_eval do
|
53
65
|
|
54
66
|
old_method = instance_method(method)
|
@@ -59,6 +71,18 @@ module ActiveSpy
|
|
59
71
|
result
|
60
72
|
end
|
61
73
|
end
|
74
|
+
old_method
|
75
|
+
end
|
76
|
+
|
77
|
+
# Properyly unpatch the +method+ in class +klass+ and put back +old_method+
|
78
|
+
# in its place.
|
79
|
+
#
|
80
|
+
def unpatch(klass, method, old_method)
|
81
|
+
ActiveSupport::Inflector.constantize(klass).class_eval do
|
82
|
+
define_method method do |*args, &block|
|
83
|
+
old_method.bind(self).call(*args, &block)
|
84
|
+
end
|
85
|
+
end
|
62
86
|
end
|
63
87
|
end
|
64
88
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_spy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Douglas Camata
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|