state_inspector 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -1
- data/lib/state_inspector/helper.rb +3 -2
- data/lib/state_inspector/reporter.rb +1 -1
- data/lib/state_inspector/snoop.rb +2 -2
- data/lib/state_inspector/state_inspector.rb +2 -2
- data/lib/state_inspector/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91d767ee5f26bb5a8d1ac2fe4020ce0740e53f56
|
4
|
+
data.tar.gz: b32d13e6c904410ea7ec8dd58526f3443ec2a372
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a07daae821a47633196917e6f92370928b508fed1878fe8a7943d93abc0cc19ef49bbc0451ca8a4e245b9006c7787f6584707de1912de0180d714d4f259a3c90
|
7
|
+
data.tar.gz: f2655063826c0b80f2c4b49cb17f693f5dffd70e41fecf0a631b3a78dd1243ca8288ce31035a8f1b772d205db0196b5bf7d62eeeec6bc8efda0c20435b926801
|
data/README.md
CHANGED
@@ -80,16 +80,21 @@ include StateInspector::Helper
|
|
80
80
|
|
81
81
|
# instead of doing MyClass.toggle_informant as above, do this.
|
82
82
|
|
83
|
+
class MyClass
|
84
|
+
attr_writer :thing
|
85
|
+
end
|
86
|
+
|
83
87
|
m = MyClass.new
|
84
88
|
observer = InternalObserver.new
|
85
89
|
|
86
90
|
# observer parameter optional. Assign beforehand if not provided here.
|
87
91
|
toggle_snoop(m, observer) do
|
88
|
-
|
92
|
+
m.thing = 4
|
89
93
|
end
|
90
94
|
|
91
95
|
# look at the results
|
92
96
|
observer.values
|
97
|
+
# => [[#<MyClass:0x00562f969dee48 @informant=false, @thing=4>, "@thing", nil, 4]]
|
93
98
|
```
|
94
99
|
|
95
100
|
When writing tests for code and using StateInspector it's very important to ensure the informant is
|
@@ -29,8 +29,9 @@ module StateInspector
|
|
29
29
|
value = yield Reporter[obj]
|
30
30
|
ensure
|
31
31
|
obj.toggle_informant
|
32
|
-
|
33
|
-
|
32
|
+
si = obj.respond_to?(:class_exec) ? obj : obj.class
|
33
|
+
obj.state_inspector.restore_methods(*si.instance_variable_get(:@state_inspector).keys)
|
34
|
+
si.remove_instance_variable(:@state_inspector)
|
34
35
|
(old_observer.nil? ? Reporter.drop(obj) : Reporter[obj] = old_observer) if observer
|
35
36
|
value
|
36
37
|
end
|
@@ -14,7 +14,7 @@ module StateInspector
|
|
14
14
|
|
15
15
|
def tell_si *args, &block
|
16
16
|
if informant?
|
17
|
-
key = self.respond_to?(:
|
17
|
+
key = self.respond_to?(:class_exec) ? self : self.class
|
18
18
|
key = Reporter.has_key?(key) ? key : self
|
19
19
|
Reporter[key].update(self, *args, &block)
|
20
20
|
end
|
@@ -22,7 +22,7 @@ module StateInspector
|
|
22
22
|
|
23
23
|
def toggle_informant
|
24
24
|
state_inspector.snoop_setters(
|
25
|
-
*(self.respond_to?(:
|
25
|
+
*(self.respond_to?(:class_exec) ? self : self.class).
|
26
26
|
instance_methods.grep(/=\z/) - Object.methods
|
27
27
|
) unless @state_inspector || self.class.instance_variable_get(:@state_inspector)
|
28
28
|
|
@@ -48,7 +48,7 @@ module StateInspector
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def restore_methods *meth0ds
|
51
|
-
base.
|
51
|
+
base.class_exec do
|
52
52
|
meth0ds.
|
53
53
|
select {|m| (@state_inspector || {}).has_key? m }.
|
54
54
|
select {|m| self == @state_inspector[m][:class] }.
|
@@ -68,7 +68,7 @@ module StateInspector
|
|
68
68
|
|
69
69
|
private
|
70
70
|
def base
|
71
|
-
if @base.respond_to? :
|
71
|
+
if @base.respond_to? :class_exec
|
72
72
|
@base
|
73
73
|
else
|
74
74
|
@base.class
|