active_spy 1.0.0 → 1.1.0

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: 63646f55b335e82ea778e8c3a4993a476be52765
4
- data.tar.gz: 2b8997b23b8593f80261ce6bfb85bffedfce549f
3
+ metadata.gz: 9c5c53150581386f90a25dccf81f694889d7dfe5
4
+ data.tar.gz: 8d082156907df01556796dcb8ff30f8d044e5c41
5
5
  SHA512:
6
- metadata.gz: 84773196a680aff01ad330c72d87f088a47f7b715f0a007582ccf103adc650442fdb6c50ed1685e9b51aa13667d521c86f9279de82241824de5f062b38e00e3a
7
- data.tar.gz: 9539e10b3494b00222b2b4e11c3ca45d313beb53303f17018a2540b363be12e83a5349354ae949b648dedbee9cc94cba3270594df74b7739844f21266b10b634
6
+ metadata.gz: f3c5bdf1f6258d88e0aa6bdabd52c37c296a8a51d68e0a6929b5f0d5bc41daac320b353cdfbc6b080687130cbf6cc28b00745d561ce1890549b54dfa341c2875
7
+ data.tar.gz: b6cedef22c6ca6adbc4ef893a698a8cfa56b8600069599e3c9a0f19ce8930f5a44610762217a70d823e62c6a06b7a73a4a139c0dfeb97b24d8422b3be81d1e3c
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
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.0.0 ruby lib
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.0.0"
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-16"
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
- # Active all the spies defined in the spy list by patching the methods
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.0.0
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-16 00:00:00.000000000 Z
11
+ date: 2014-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport