message-recorder 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,10 @@
1
+ == 1.0.1 2008-02-13
2
+
3
+ * 1 major enhancement:
4
+ * before and after filters are simplified.
5
+ * Added Array extension
6
+ * Added Object extension
7
+
1
8
  == 1.0.0 2008-02-13
2
9
 
3
10
  * 1 major enhancement:
@@ -5,6 +5,8 @@ README.txt
5
5
  Rakefile
6
6
  config/hoe.rb
7
7
  config/requirements.rb
8
+ lib/extentions/array.rb
9
+ lib/extentions/object.rb
8
10
  lib/message-recorder.rb
9
11
  lib/message-recorder/branching_mock.rb
10
12
  lib/message-recorder/chain.rb
@@ -65,6 +65,7 @@ hoe = Hoe.new(GEM_NAME, VERS) do |p|
65
65
  end
66
66
 
67
67
  CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
68
- PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
68
+ # PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
69
+ PATH = RUBYFORGE_PROJECT
69
70
  hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
70
71
  hoe.rsync_args = '-av --delete --ignore-errors'
@@ -0,0 +1,28 @@
1
+ # Copyright (c) 2008 Simon Menke
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ class Array
23
+
24
+ # send each entry to a recorder. (using Message::Recorder#send_to)
25
+ def each_play(recorder)
26
+ each { |object| object.play(recorder) }
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ # Copyright (c) 2008 Simon Menke
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ class Object
23
+
24
+ # send the receiver to a recorder. (using Message::Recorder#send_to)
25
+ def play(recorder)
26
+ recorder.send_to(self)
27
+ end
28
+ end
@@ -29,3 +29,6 @@ require File.join(File.dirname(__FILE__), "message-recorder", "chain")
29
29
  require File.join(File.dirname(__FILE__), "message-recorder", "collector")
30
30
  require File.join(File.dirname(__FILE__), "message-recorder", "branching_mock")
31
31
  require File.join(File.dirname(__FILE__), "message-recorder", "chaining_mock")
32
+
33
+ require File.join(File.dirname(__FILE__), "extentions", "object")
34
+ require File.join(File.dirname(__FILE__), "extentions", "array")
@@ -32,9 +32,10 @@ class Message::Recorder::Chain < ::Array # :nodoc:
32
32
 
33
33
  def send_to(subject_, recorder)
34
34
  inject(subject_) do |subject,message|
35
- return nil if recorder.break_if.call(subject)
36
-
37
- message.send_to(subject, recorder)
35
+ return nil unless recorder.filter_before(subject, message.method_name, message.arguments)
36
+ new_subject = message.send_to(subject, recorder)
37
+ recorder.filter_after(subject, message.method_name, message.arguments, new_subject)
38
+ new_subject
38
39
  end
39
40
  end
40
41
 
@@ -30,12 +30,7 @@ class Message::Recorder::Message # :nodoc:
30
30
  end
31
31
 
32
32
  def send_to(subject, recorder)
33
- recorder.before_call.call(subject, self.method_name, self.arguments)
34
-
35
- result = subject.__send__(self.method_name, *self.arguments, &self.block)
36
-
37
- recorder.after_call.call(subject, self.method_name, self.arguments, result)
38
- result
33
+ subject.__send__(self.method_name, *self.arguments, &self.block)
39
34
  end
40
35
 
41
36
  def arguments
@@ -19,52 +19,72 @@
19
19
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
20
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
- #
22
+ # Example:
23
+ # recorder = Message::Recorder.new
24
+ # recorder.record.downcase.intern
25
+ # recorder.before do |subject, method, arguments|
26
+ # !(subject.nil? or subject.empty?)
27
+ # end
28
+ # recorder.after do |subject, method, arguments, return_value|
29
+ # p return_value
30
+ # end
31
+ # recorder.send_to(nil) # => nil
32
+ # recorder.send_to("") # => nil
33
+ # recorder.send_to("Mr_Henry") # => :mr_henry
23
34
  class Message::Recorder
24
35
 
25
- # a Proc with one argument
26
- # recorder.break_if = Proc.new { |subject| subject.nil? }
27
- # if the Proc returns false the chain will be broken.
28
- attr_writer :break_if
29
-
30
- # a Proc with three arguments
31
- # recorder.before_call = Proc.new { |subject, method, arguments| ... }
32
- attr_writer :before_call
33
-
34
- # a Proc with four arguments
35
- # recorder.after_call = Proc.new { |subject, method, arguments, return_value| ... }
36
- attr_writer :after_call
36
+ # Takes a block with three arguments
37
+ # recorder.before { |subject, method, arguments| ... }
38
+ # if the block returns false the chain will be broken.
39
+ def before(&block)
40
+ before_filters << block
41
+ end
37
42
 
38
- def initialize # :nodoc:
39
- @collector = nil
40
- before_call = nil
41
- after_call = nil
42
- break_if = nil
43
+ # Takes a block with four arguments
44
+ # recorder.after { |subject, method, arguments, return_value| ... }
45
+ def after(&block)
46
+ after_filters << block
43
47
  end
44
48
 
45
49
  # #record returns a mock object which will store all the messages you send to it.
46
50
  def record
47
- @collector = ::Message::Recorder::Collector.new
48
- @collector.collect_messages
51
+ collector = nil
52
+ collector.collect_messages
49
53
  end
50
54
 
51
55
  # #send_to will send the recorded messages to the #subject.
52
56
  def send_to(subject)
53
- @collector.send_to(subject, self)
57
+ collector.send_to(subject, self)
54
58
  end
55
59
 
56
60
 
61
+ attr_accessor :before_filters # :nodoc:
62
+ attr_accessor :after_filters # :nodoc:
63
+
64
+ def before_filters # :nodoc:
65
+ @before_filters ||= []
66
+ end
67
+
68
+ def after_filters # :nodoc:
69
+ @before_filters ||= []
70
+ end
57
71
 
58
- def break_if # :nodoc:
59
- @break_if ||= Proc.new { |f| false }
72
+ def filter_before(subject, method, arguments) # :nodoc:
73
+ before_filters.each do |filter|
74
+ should_break = filter.call(subject, method, arguments)
75
+ return false if should_break === false
76
+ end
77
+ return true
60
78
  end
61
79
 
62
- def before_call # :nodoc:
63
- @before_call ||= Proc.new { |f, m, args| nil }
80
+ def filter_after(subject, method, arguments, return_value) # :nodoc:
81
+ after_filters.each do |filter|
82
+ filter.call(subject, method, arguments, return_value)
83
+ end
64
84
  end
65
85
 
66
- def after_call # :nodoc:
67
- @after_call ||= Proc.new { |f, m, args, result| nil }
86
+ def collector # :nodoc:
87
+ @collector ||= ::Message::Recorder::Collector.new
68
88
  end
69
89
 
70
90
  end
@@ -23,7 +23,7 @@ module Message #:nodoc:
23
23
  module VERSION #:nodoc:
24
24
  MAJOR = 1
25
25
  MINOR = 0
26
- TINY = 0
26
+ TINY = 1
27
27
 
28
28
  STRING = [MAJOR, MINOR, TINY].join('.')
29
29
  end
@@ -33,7 +33,7 @@
33
33
  <h1>message recorder</h1>
34
34
  <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/message-recorder"; return false'>
35
35
  <p>Get Version</p>
36
- <a href="http://rubyforge.org/projects/message-recorder" class="numbers">1.0.0</a>
36
+ <a href="http://rubyforge.org/projects/message-recorder" class="numbers">1.0.1</a>
37
37
  </div>
38
38
  <h2>&#x2192; &#8216;message-recorder&#8217;</h2>
39
39
 
@@ -53,6 +53,9 @@
53
53
  <h2>The basics</h2>
54
54
 
55
55
 
56
+ <p>The rdocs are <a href="http://message-recorde.rubyforge.org/rdoc/">here</a></p>
57
+
58
+
56
59
  <p>This snippet will first record a <tt>downcase</tt> message and after that it will replay the recorded messages on some objects.</p>
57
60
 
58
61
 
@@ -119,7 +122,7 @@
119
122
 
120
123
  <p>Comments are welcome. Send an email to <a href="mailto:simon@5xm.org">Simon Menke</a></p>
121
124
  <p class="coda">
122
- <a href="simon@5xm.org">Simon Menke</a>, 14th February 2008<br>
125
+ <a href="simon@5xm.org">Simon Menke</a>, 15th February 2008<br>
123
126
  Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
124
127
  </p>
125
128
  </div>
@@ -13,6 +13,8 @@ h2. Installing
13
13
 
14
14
  h2. The basics
15
15
 
16
+ The rdocs are "here":http://message-recorde.rubyforge.org/rdoc/
17
+
16
18
  This snippet will first record a <tt>downcase</tt> message and after that it will replay the recorded messages on some objects.
17
19
 
18
20
  <pre syntax="ruby">
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: message-recorder
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Menke
@@ -34,6 +34,8 @@ files:
34
34
  - Rakefile
35
35
  - config/hoe.rb
36
36
  - config/requirements.rb
37
+ - lib/extentions/array.rb
38
+ - lib/extentions/object.rb
37
39
  - lib/message-recorder.rb
38
40
  - lib/message-recorder/branching_mock.rb
39
41
  - lib/message-recorder/chain.rb