markevans-method_call_recorder 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.2.0
@@ -1,6 +1,5 @@
1
1
  class MethodCall
2
2
 
3
-
4
3
  def initialize(meth, *args, &blk)
5
4
  @method, @args = meth, args
6
5
  @block = blk
@@ -0,0 +1,17 @@
1
+ class MethodCallLogger
2
+
3
+ def initialize
4
+ @recorders = []
5
+ @method_log = []
6
+ end
7
+
8
+ def register(*rec_objects)
9
+ rec_objects.each do |rec|
10
+ rec._on_method_call{|r| method_log << [r, r._last_method] }
11
+ recorders << rec
12
+ end
13
+ end
14
+
15
+ attr_reader :recorders, :method_log
16
+
17
+ end
@@ -9,10 +9,18 @@ class MethodCallRecorder
9
9
  end
10
10
  end
11
11
 
12
+ def _on_method_call(&blk)
13
+ @on_method_call = blk
14
+ end
15
+
12
16
  def _first_method
13
17
  _method_chain.first
14
18
  end
15
19
 
20
+ def _last_method
21
+ _method_chain.last
22
+ end
23
+
16
24
  def _empty?
17
25
  _method_chain.empty?
18
26
  end
@@ -52,6 +60,7 @@ class MethodCallRecorder
52
60
 
53
61
  def method_missing(meth, *args, &blk)
54
62
  _method_chain << MethodCall.new(meth, *args, &blk)
63
+ @on_method_call.call(self) if @on_method_call
55
64
  self
56
65
  end
57
66
 
@@ -1,3 +1,3 @@
1
- %w{method_call method_call_recorder}.each do |file|
1
+ %w{method_call method_call_recorder method_call_logger}.each do |file|
2
2
  require File.dirname(__FILE__)+'/method_call_recorder/'+file
3
3
  end
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{method_call_recorder}
5
- s.version = "0.1.2"
5
+ s.version = "0.2.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Mark Evans"]
9
- s.date = %q{2009-07-29}
9
+ s.date = %q{2009-07-31}
10
10
  s.email = %q{mark@new-bamboo.co.uk}
11
11
  s.extra_rdoc_files = [
12
12
  "LICENSE",
@@ -21,8 +21,10 @@ Gem::Specification.new do |s|
21
21
  "VERSION",
22
22
  "lib/method_call_recorder.rb",
23
23
  "lib/method_call_recorder/method_call.rb",
24
+ "lib/method_call_recorder/method_call_logger.rb",
24
25
  "lib/method_call_recorder/method_call_recorder.rb",
25
26
  "method_call_recorder.gemspec",
27
+ "spec/method_call_logger_spec.rb",
26
28
  "spec/method_call_recorder_spec.rb",
27
29
  "spec/method_call_spec.rb",
28
30
  "spec/spec_helper.rb"
@@ -34,7 +36,8 @@ Gem::Specification.new do |s|
34
36
  s.rubygems_version = %q{1.3.1}
35
37
  s.summary = %q{An object on which you can call anything, where nothing happens, but the whole method chain is recorded}
36
38
  s.test_files = [
37
- "spec/method_call_recorder_spec.rb",
39
+ "spec/method_call_logger_spec.rb",
40
+ "spec/method_call_recorder_spec.rb",
38
41
  "spec/method_call_spec.rb",
39
42
  "spec/spec_helper.rb"
40
43
  ]
@@ -0,0 +1,27 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe MethodCallLogger do
4
+
5
+ describe "registering" do
6
+ before(:each) do
7
+ @logger = MethodCallLogger.new
8
+ @rec1, @rec2, @rec3 = MethodCallRecorder.new, MethodCallRecorder.new, MethodCallRecorder.new
9
+ end
10
+ it "should return the registered method call recorders" do
11
+ @logger.register @rec1
12
+ @logger.register @rec2, @rec3
13
+ @logger.recorders.should == [@rec1,@rec2,@rec3]
14
+ end
15
+ it "should log each time a method is called" do
16
+ @logger.register @rec1, @rec2
17
+ @rec2.eat[2]
18
+ @rec1.as_well
19
+ @logger.method_log.should == [
20
+ [@rec2, MethodCall.new(:eat)],
21
+ [@rec2, MethodCall.new(:[],2)],
22
+ [@rec1, MethodCall.new(:as_well)]
23
+ ]
24
+ end
25
+ end
26
+
27
+ end
@@ -127,4 +127,13 @@ describe MethodCallRecorder do
127
127
  end
128
128
  end
129
129
 
130
+ describe "callback on method call" do
131
+ it "should do the callback on every method call" do
132
+ methods = []
133
+ @rec._on_method_call{|rec| methods << rec._last_method.method }
134
+ @rec.hi[:there]
135
+ methods.should == [:hi,:[]]
136
+ end
137
+ end
138
+
130
139
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markevans-method_call_recorder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Evans
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-29 00:00:00 -07:00
12
+ date: 2009-07-31 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -31,8 +31,10 @@ files:
31
31
  - VERSION
32
32
  - lib/method_call_recorder.rb
33
33
  - lib/method_call_recorder/method_call.rb
34
+ - lib/method_call_recorder/method_call_logger.rb
34
35
  - lib/method_call_recorder/method_call_recorder.rb
35
36
  - method_call_recorder.gemspec
37
+ - spec/method_call_logger_spec.rb
36
38
  - spec/method_call_recorder_spec.rb
37
39
  - spec/method_call_spec.rb
38
40
  - spec/spec_helper.rb
@@ -64,6 +66,7 @@ signing_key:
64
66
  specification_version: 2
65
67
  summary: An object on which you can call anything, where nothing happens, but the whole method chain is recorded
66
68
  test_files:
69
+ - spec/method_call_logger_spec.rb
67
70
  - spec/method_call_recorder_spec.rb
68
71
  - spec/method_call_spec.rb
69
72
  - spec/spec_helper.rb