state_inspector 1.0.0.rc1 → 1.0.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: 7e7bd7bd17c476a6dc4860357ebfc4a827b2d7ed
4
- data.tar.gz: 8d046a1fa6385c108e45b321c50a3a8091ff6602
3
+ metadata.gz: c7830abc050b3b176596bcbbd359b0170010004e
4
+ data.tar.gz: 733bee9156bba95c6af439b1051847fca8432406
5
5
  SHA512:
6
- metadata.gz: 5b4210564e7f9fee7f03d54cb8d2bcd779d616844940a6cc82b592b3fb35737e4ed9928008b891cb076ab900d5e2aab939cf690addf052ff3dc1b4fef5d18623
7
- data.tar.gz: 1540ec589c07d4c6cf5dc14f3887d833244a3b6d0cb8063606759b88c743629e0ea1f4ac74406536f5d36e2b66a001d22ab0c3227571ef4f0640c01ff8807c9c
6
+ metadata.gz: 911dac749063d37fb90185a8502f81f00f3ebf273455210c8eb807be2beca505f3b279bc418d57f59df1e2f568f142229b2ebcdc879177a62f2692c8a5089b9f
7
+ data.tar.gz: 407a7b7582fae7e6ea3a235d5f0a353a3c7ac096417df06de33ac0e08d63b5a4d2bbdf5923354de25444fd865d2ea0d15921322e2aa497439a18a8edf9bd4ef3
data/README.md CHANGED
@@ -156,7 +156,7 @@ And to register this observer to a target class you simply write:
156
156
  StateInspector::Reporter[MyTargetClass] = ExampleObserver
157
157
  ```
158
158
 
159
- ## Manually Create Informers
159
+ ## Manually Create or Remove Informers
160
160
 
161
161
  To manually create informant methods use `state_inspector.snoop_setters :a=, :b=` and
162
162
  `state_inspector.snoop_methods :a, :b`.
@@ -196,6 +196,17 @@ StateInspector::Reporter[MyClass].values
196
196
  ```
197
197
  The nils in the values above represent the previous value the instance variable returned.
198
198
 
199
+ #### Remove Informers
200
+
201
+ To remove informers simply use `state_inspector.restore_methods`. This takes out the hook from
202
+ each method that waits for the `informer?` method to be true.
203
+
204
+ ```ruby
205
+ # continuing from the above example
206
+
207
+ m.state_inspector.restore_methods :b=, :c=, :x
208
+ ```
209
+
199
210
  ## Reporter Legend
200
211
 
201
212
  The format of a report sent will always start with the object that sent it; aka `self`. Next you will
@@ -13,9 +13,8 @@ module StateInspector
13
13
  yield
14
14
  ensure
15
15
  obj.toggle_informant
16
- obj.instance_exec {@state_inspector = nil} if obj.
17
- instance_variable_get(:@state_inspector).
18
- tap {|h| h.is_a?(Hash) ? h.empty? : h}
16
+ (obj.respond_to?(:class_eval) ? obj : obj.class).
17
+ remove_instance_variable(:@state_inspector)
19
18
  end
20
19
  end
21
20
  end
@@ -7,15 +7,19 @@ module StateInspector
7
7
  def snoop_setters *setters
8
8
  base.class_exec do
9
9
  setters.
10
- delete_if {|m| (@state_inspector ||= {}).fetch(m){ nil } }.
10
+ delete_if {|m| (@state_inspector || {}).fetch(m){ nil } }.
11
11
  each do |m|
12
- (@state_inspector ||= {})[m] = __method__
13
12
  single = singleton_methods.include? m
14
- original_method = (single ? singleton_method(m) : instance_method(m))
13
+ original_method = (single ? singleton_method(m).unbind : instance_method(m))
14
+ (@state_inspector ||= {})[m] = {
15
+ contructor: __method__,
16
+ class: self,
17
+ singleton_method: single,
18
+ original_method: original_method
19
+ }
15
20
  send((single ? :define_singleton_method : :define_method), m) do |*args, &block|
16
21
  var = "@#{__method__.to_s.chop}"
17
22
  tell_si var, instance_variable_get(var), *args, &block
18
- original_method = (single ? original_method.unbind : original_method)
19
23
  original_method.bind(self).call(*args, &block)
20
24
  end
21
25
  end
@@ -25,20 +29,38 @@ module StateInspector
25
29
  def snoop_methods *meth0ds
26
30
  base.class_exec do
27
31
  meth0ds.
28
- delete_if {|m| (@state_inspector ||= {}).fetch(m){ nil } }.
32
+ delete_if {|m| (@state_inspector || {}).fetch(m){ nil } }.
29
33
  each do |m|
30
- (@state_inspector ||= {})[m] = __method__
31
34
  single = singleton_methods.include? m
32
- original_method = (single ? singleton_method(m) : instance_method(m))
35
+ original_method = (single ? singleton_method(m).unbind : instance_method(m))
36
+ (@state_inspector ||= {})[m] = {
37
+ contructor: __method__,
38
+ class: self,
39
+ singleton_method: single,
40
+ original_method: original_method
41
+ }
33
42
  send((single ? :define_singleton_method : :define_method), m) do |*args, &block|
34
43
  tell_si __method__, *args, &block
35
- original_method = (single ? original_method.unbind : original_method)
36
44
  original_method.bind(self).call(*args, &block)
37
45
  end
38
46
  end
39
47
  end
40
48
  end
41
49
 
50
+ def restore_methods *meth0ds
51
+ base.class_eval do
52
+ meth0ds.
53
+ select {|m| (@state_inspector || {}).has_key? m }.
54
+ select {|m| self == @state_inspector[m][:class] }.
55
+ each do |m|
56
+ definer = @state_inspector[m][:singleton_method] ? :define_singleton_method : :define_method
57
+ meth0d = send(definer, m, @state_inspector[m][:original_method])
58
+ @state_inspector.delete(m)
59
+ meth0d
60
+ end
61
+ end
62
+ end
63
+
42
64
  def skip_setter_snoops
43
65
  base.instance_variable_set(:@state_inspector, Hash.new) unless base.
44
66
  instance_variable_defined? :@state_inspector
@@ -1,3 +1,3 @@
1
1
  module StateInspector
2
- VERSION = "1.0.0.rc1"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Daniel P. Clark"]
10
10
  spec.email = ["6ftdan@gmail.com"]
11
11
 
12
- spec.summary = %q{Introspection tool for reporting state change.}
13
- spec.description = %q{Introspection tool for reporting state change. Instance varialbes and method call debugging.}
12
+ spec.summary = %q{Introspection tool for reporting method calls and state change.}
13
+ spec.description = %q{Introspection tool for reporting method calls and state change. Instance variables and method call debugging.}
14
14
  spec.homepage = "https://github.com/danielpclark/state_inspector"
15
15
  spec.license = "MIT"
16
16
 
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.0.rc1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel P. Clark
@@ -80,8 +80,8 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.0'
83
- description: Introspection tool for reporting state change. Instance varialbes and
84
- method call debugging.
83
+ description: Introspection tool for reporting method calls and state change. Instance
84
+ variables and method call debugging.
85
85
  email:
86
86
  - 6ftdan@gmail.com
87
87
  executables: []
@@ -123,13 +123,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
123
123
  version: '0'
124
124
  required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  requirements:
126
- - - ">"
126
+ - - ">="
127
127
  - !ruby/object:Gem::Version
128
- version: 1.3.1
128
+ version: '0'
129
129
  requirements: []
130
130
  rubyforge_project:
131
131
  rubygems_version: 2.6.8
132
132
  signing_key:
133
133
  specification_version: 4
134
- summary: Introspection tool for reporting state change.
134
+ summary: Introspection tool for reporting method calls and state change.
135
135
  test_files: []