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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fe629c67e180cfa586f4543e4d0bb416fa1694e1
4
- data.tar.gz: 14cf88964e95a255333b1890aac132ca45df850f
3
+ metadata.gz: 91d767ee5f26bb5a8d1ac2fe4020ce0740e53f56
4
+ data.tar.gz: b32d13e6c904410ea7ec8dd58526f3443ec2a372
5
5
  SHA512:
6
- metadata.gz: 6499a6c6fd0b6d43e0b14e9b9677fd57ed5a7e185e845ff910f7a563221f9b08974cc38a8add1199af3c70dc4cb6b61970f15158db0aca072c69c7fbcb280032
7
- data.tar.gz: c7af11123487b76d83de3c3653869275e2cbda55c0dacfc3ced4fd5e4a9e175ba53b6a7d08034c7a566fcbbef81890fa5512009c82009af9d5b1aac0d339d543
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
- # put your own code here
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
- (obj.respond_to?(:class_eval) ? obj : obj.class).
33
- remove_instance_variable(:@state_inspector)
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
@@ -18,7 +18,7 @@ module StateInspector
18
18
  end
19
19
 
20
20
  def has_observer? key
21
- class_key = key.respond_to?(:class_eval) ? key : key.class
21
+ class_key = key.respond_to?(:class_exec) ? key : key.class
22
22
  reporters.has_key?(key) || reporters.has_key?(class_key)
23
23
  end
24
24
 
@@ -14,7 +14,7 @@ module StateInspector
14
14
 
15
15
  def tell_si *args, &block
16
16
  if informant?
17
- key = self.respond_to?(:class_eval) ? self : self.class
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?(:class_eval) ? self : self.class).
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.class_eval do
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? :class_eval
71
+ if @base.respond_to? :class_exec
72
72
  @base
73
73
  else
74
74
  @base.class
@@ -1,3 +1,3 @@
1
1
  module StateInspector
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: state_inspector
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel P. Clark