Class: MethodCallRecorder
- Inherits:
-
Object
- Object
- MethodCallRecorder
show all
- Defined in:
- lib/method_call_recorder/method_call_recorder.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args) ⇒ Object
53
54
55
56
|
# File 'lib/method_call_recorder/method_call_recorder.rb', line 53
def method_missing(meth, *args)
_method_chain << MethodCall.new(meth, *args)
self
end
|
Instance Attribute Details
#_method_chain ⇒ Object
24
25
26
|
# File 'lib/method_call_recorder/method_call_recorder.rb', line 24
def _method_chain
@_method_chain ||= []
end
|
Instance Method Details
#_empty? ⇒ Boolean
16
17
18
|
# File 'lib/method_call_recorder/method_call_recorder.rb', line 16
def _empty?
_method_chain.empty?
end
|
#_first_method ⇒ Object
12
13
14
|
# File 'lib/method_call_recorder/method_call_recorder.rb', line 12
def _first_method
_method_chain.first
end
|
#_play(object, &blk) ⇒ Object
3
4
5
6
7
8
9
10
|
# File 'lib/method_call_recorder/method_call_recorder.rb', line 3
def _play(object, &blk)
i = 0
_method_chain.inject(object) do |obj, method_call|
i += 1
yield(obj, method_call, _method_chain[i]) if block_given?
method_call.call_on(obj)
end
end
|
#_reset! ⇒ Object
35
36
37
|
# File 'lib/method_call_recorder/method_call_recorder.rb', line 35
def _reset!
self._method_chain = []
end
|
#_select(meth, args = nil) ⇒ Object
39
40
41
42
43
44
45
|
# File 'lib/method_call_recorder/method_call_recorder.rb', line 39
def _select(meth, args=nil)
_method_chain.select do |method_call|
selected = (method_call.method == meth)
selected &&= (method_call.args == args) if args
selected
end
end
|
#_to_setter(value) ⇒ Object
28
29
30
31
32
33
|
# File 'lib/method_call_recorder/method_call_recorder.rb', line 28
def _to_setter(value)
new_rec = self.dup
new_rec._method_chain = self._method_chain.dup
new_rec._method_chain[-1] = self._method_chain[-1].to_setter(value)
new_rec
end
|
#to_s ⇒ Object
20
21
22
|
# File 'lib/method_call_recorder/method_call_recorder.rb', line 20
def to_s
_method_chain.inspect
end
|