message-recorder 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,26 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe Message::Recorder::Chain do
4
+
5
+ before do
6
+ @recorder = Message::Recorder.new
7
+ end
8
+
9
+ it "should record" do
10
+ chain = Message::Recorder::Chain.new
11
+ chain.record(:downcase)
12
+ chain.record(:+, " world")
13
+
14
+ chain.size.should be_eql(2)
15
+ chain.send_to("HELLO",@recorder).should be_eql("hello world")
16
+ end
17
+
18
+ it "should dup properly" do
19
+ chain = Message::Recorder::Chain.new
20
+ chain.record(:downcase)
21
+ chain.record(:+, " world")
22
+
23
+ chain.dup.should be_eql(chain)
24
+ end
25
+
26
+ end
@@ -0,0 +1,77 @@
1
+
2
+ require "pp"
3
+ require File.dirname(__FILE__) + '/spec_helper'
4
+
5
+ describe Message::Recorder::Collector do
6
+
7
+ before do
8
+ @recorder = Message::Recorder.new
9
+ end
10
+
11
+ it "should record" do
12
+ chain = Message::Recorder::Collector.new
13
+ chain.record(:downcase)
14
+ chain.record(:+, " world")
15
+
16
+ chain.size.should be_eql(1)
17
+ chain.first.size.should be_eql(2)
18
+ chain.send_to("HELLO", @recorder).should be_eql(["hello world"])
19
+ end
20
+
21
+ it "should branch" do
22
+ chain = Message::Recorder::Collector.new
23
+ chain.record(:downcase)
24
+ chain.record(:+, " world")
25
+
26
+ chain.size.should be_eql(1)
27
+ chain.first.size.should be_eql(2)
28
+ chain.send_to("HELLO", @recorder).should be_eql(["hello world"])
29
+
30
+ branch = chain.branch
31
+ branch.record(:+, "!")
32
+ branch.size.should be_eql(1)
33
+ branch.first.size.should be_eql(3)
34
+ branch.send_to("HELLO", @recorder).should be_eql(["hello world!"])
35
+
36
+ branch.should_not be_equal(chain)
37
+ end
38
+
39
+ it "should collect a single chain" do
40
+ collector = Message::Recorder::Collector.new
41
+ collector.collect_messages.downcase + " world"
42
+
43
+ collector.size.should be_eql(1)
44
+ collector.send_to("HELLO", @recorder).should be_eql(["hello world"])
45
+ end
46
+
47
+ it "should collect a branched chain" do
48
+ collector = Message::Recorder::Collector.new
49
+ collector.collect_messages.downcase.with_results do
50
+ intern
51
+ capitalize
52
+ end
53
+
54
+ collector.size.should be_eql(2)
55
+ collector.first.size.should be_eql(2)
56
+ collector.last.size.should be_eql(2)
57
+ collector.send_to("HELLO",@recorder).should ==([:hello, "Hello"])
58
+ end
59
+
60
+ it "should collect a branched chain" do
61
+ collector = Message::Recorder::Collector.new
62
+ collector.collect_messages.compact.with_results do
63
+ collect { |s| s.intern }
64
+ collect { |s| s.capitalize }.with_results do
65
+ collect { |s| s.concat " world" }
66
+ collect { |s| s.concat " simon" }
67
+ end.with_results do
68
+ collect { |s| s.concat "!" }
69
+ collect { |s| s.concat "?" }
70
+ end
71
+ end
72
+
73
+ expected = [[:hello, :bye], ["Hello world!", "Bye world!"], ["Hello simon!", "Bye simon!"], ["Hello world?", "Bye world?"], ["Hello simon?", "Bye simon?"]]
74
+ collector.send_to([nil, "hello", nil, "bye", nil], @recorder).should == expected
75
+ end
76
+
77
+ end
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe Message::Recorder do
4
+
5
+ it "should dup properly" do
6
+ chain = Message::Recorder::Chain.new
7
+ chain.record(:downcase)
8
+ chain.record(:+, " world")
9
+
10
+ chain.dup.should be_eql(chain)
11
+ end
12
+
13
+ end
@@ -0,0 +1,89 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe Message::Recorder::Message do
4
+
5
+ before do
6
+ @recorder = Message::Recorder.new
7
+ end
8
+
9
+ it "should init properly (with all arguments)" do
10
+ message = Message::Recorder::Message.new(:inject, 0) { |sum, n| sum += n }
11
+ message.method_name.should be_eql(:inject)
12
+ message.arguments.should be_eql([0])
13
+ message.block.should_not be_nil
14
+ end
15
+
16
+ it "should init properly (with all arguments, except block)" do
17
+ message = Message::Recorder::Message.new(:inject, 0)
18
+ message.method_name.should be_eql(:inject)
19
+ message.arguments.should be_eql([0])
20
+ message.block.should_not be_nil
21
+ end
22
+
23
+ it "should init properly (with all arguments, except m_arguments)" do
24
+ message = Message::Recorder::Message.new(:inject) { |sum, n| sum += n }
25
+ message.method_name.should be_eql(:inject)
26
+ message.arguments.should be_eql([])
27
+ message.block.should_not be_nil
28
+ end
29
+
30
+ it "should init properly (with all arguments, except block m_arguments)" do
31
+ message = Message::Recorder::Message.new(:inject)
32
+ message.method_name.should be_eql(:inject)
33
+ message.arguments.should be_eql([])
34
+ message.block.should_not be_nil
35
+ end
36
+
37
+ it "should send itself properly to a subject (without arguments and block)" do
38
+ message = Message::Recorder::Message.new(:downcase)
39
+ message.send_to("HELLO", @recorder).should be_eql("hello")
40
+ end
41
+
42
+ it "should send itself properly to a subject (without block)" do
43
+ message = Message::Recorder::Message.new(:+, " world")
44
+ message.send_to("hello", @recorder).should be_eql("hello world")
45
+ end
46
+
47
+ it "should send itself properly to a subject (without arguments)" do
48
+ message = Message::Recorder::Message.new(:inject) { |sum, n| sum + n }
49
+ message.send_to([1,2,3], @recorder).should be_eql(6)
50
+ end
51
+
52
+ it "should send itself properly to a subject" do
53
+ message = Message::Recorder::Message.new(:inject, 6) { |sum, n| sum + n }
54
+ message.send_to([1,2,3], @recorder).should be_eql(12)
55
+ end
56
+
57
+ it "should dup properly (with all arguments)" do
58
+ message = Message::Recorder::Message.new(:inject, 0) { |sum, n| sum += n }
59
+ message = message.dup
60
+ message.method_name.should be_eql(:inject)
61
+ message.arguments.should be_eql([0])
62
+ message.block.should_not be_nil
63
+ end
64
+
65
+ it "should dup properly (with all arguments, except block)" do
66
+ message = Message::Recorder::Message.new(:inject, 0)
67
+ message = message.dup
68
+ message.method_name.should be_eql(:inject)
69
+ message.arguments.should be_eql([0])
70
+ message.block.should_not be_nil
71
+ end
72
+
73
+ it "should dup properly (with all arguments, except m_arguments)" do
74
+ message = Message::Recorder::Message.new(:inject) { |sum, n| sum += n }
75
+ message = message.dup
76
+ message.method_name.should be_eql(:inject)
77
+ message.arguments.should be_eql([])
78
+ message.block.should_not be_nil
79
+ end
80
+
81
+ it "should dup properly (with all arguments, except block m_arguments)" do
82
+ message = Message::Recorder::Message.new(:inject)
83
+ message = message.dup
84
+ message.method_name.should be_eql(:inject)
85
+ message.arguments.should be_eql([])
86
+ message.block.should_not be_nil
87
+ end
88
+
89
+ end
@@ -0,0 +1,2 @@
1
+ --colour
2
+ -f specdoc
@@ -0,0 +1,9 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ require File.join(File.dirname(__FILE__), "..", "lib", "message-recorder")
@@ -0,0 +1,34 @@
1
+ desc 'Release the website and new gem version'
2
+ task :deploy => [:check_version, :website, :release] do
3
+ puts "Remember to create SVN tag:"
4
+ puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
5
+ "svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
6
+ puts "Suggested comment:"
7
+ puts "Tagging release #{CHANGES}"
8
+ end
9
+
10
+ desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
11
+ task :local_deploy => [:website_generate, :install_gem]
12
+
13
+ task :check_version do
14
+ unless ENV['VERSION']
15
+ puts 'Must pass a VERSION=x.y.z release version'
16
+ exit
17
+ end
18
+ unless ENV['VERSION'] == VERS
19
+ puts "Please update your version.rb to match the release version, currently #{VERS}"
20
+ exit
21
+ end
22
+ end
23
+
24
+ desc 'Install the package as a gem, without generating documentation(ri/rdoc)'
25
+ task :install_gem_no_doc => [:clean, :package] do
26
+ sh "#{'sudo ' unless Hoe::WINDOZE }gem install pkg/*.gem --no-rdoc --no-ri"
27
+ end
28
+
29
+ namespace :manifest do
30
+ desc 'Recreate Manifest.txt to include ALL files'
31
+ task :refresh do
32
+ `rake check_manifest | patch -p0 > Manifest.txt`
33
+ end
34
+ end
@@ -0,0 +1,7 @@
1
+ task :ruby_env do
2
+ RUBY_APP = if RUBY_PLATFORM =~ /java/
3
+ "jruby"
4
+ else
5
+ "ruby"
6
+ end unless defined? RUBY_APP
7
+ end
@@ -0,0 +1,25 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ require 'spec'
6
+ end
7
+ begin
8
+ require 'spec/rake/spectask'
9
+ rescue LoadError
10
+ puts <<-EOS
11
+ To use rspec for testing you must install rspec gem:
12
+ gem install rspec
13
+ EOS
14
+ exit(0)
15
+ end
16
+
17
+ module Spec
18
+ class << self; def run; false; end; end
19
+ end
20
+
21
+ desc "Run the specs under spec/models"
22
+ Spec::Rake::SpecTask.new do |t|
23
+ t.spec_opts = ['--options', "spec/spec.opts"]
24
+ t.spec_files = FileList['spec/*_spec.rb']
25
+ end
@@ -0,0 +1,17 @@
1
+ desc 'Generate website files'
2
+ task :website_generate => :ruby_env do
3
+ (Dir['website/**/*.txt'] - Dir['website/version*.txt']).each do |txt|
4
+ sh %{ #{RUBY_APP} script/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
5
+ end
6
+ end
7
+
8
+ desc 'Upload website files to rubyforge'
9
+ task :website_upload do
10
+ host = "#{rubyforge_username}@rubyforge.org"
11
+ remote_dir = "/var/www/gforge-projects/#{PATH}/"
12
+ local_dir = 'website'
13
+ sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
14
+ end
15
+
16
+ desc 'Generate and upload website files'
17
+ task :website => [:website_generate, :website_upload, :publish_docs]
@@ -0,0 +1,130 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" />
6
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
7
+ <title>
8
+ message recorder
9
+ </title>
10
+ <script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
11
+ <style>
12
+
13
+ </style>
14
+ <script type="text/javascript">
15
+ window.onload = function() {
16
+ settings = {
17
+ tl: { radius: 10 },
18
+ tr: { radius: 10 },
19
+ bl: { radius: 10 },
20
+ br: { radius: 10 },
21
+ antiAlias: true,
22
+ autoPad: true,
23
+ validTags: ["div"]
24
+ }
25
+ var versionBox = new curvyCorners(settings, document.getElementById("version"));
26
+ versionBox.applyCornersToAll();
27
+ }
28
+ </script>
29
+ </head>
30
+ <body>
31
+ <div id="main">
32
+
33
+ <h1>message recorder</h1>
34
+ <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/message-recorder"; return false'>
35
+ <p>Get Version</p>
36
+ <a href="http://rubyforge.org/projects/message-recorder" class="numbers">1.0.0</a>
37
+ </div>
38
+ <h2>&#x2192; &#8216;message-recorder&#8217;</h2>
39
+
40
+
41
+ <h2>What</h2>
42
+
43
+
44
+ <p><tt>Message::Recorder</tt> is a tool to record messages send to Ruby objects.</p>
45
+
46
+
47
+ <h2>Installing</h2>
48
+
49
+
50
+ <p><pre class='syntax'><span class="ident">sudo</span> <span class="ident">gem</span> <span class="ident">install</span> <span class="ident">message</span><span class="punct">-</span><span class="ident">recorder</span></pre></p>
51
+
52
+
53
+ <h2>The basics</h2>
54
+
55
+
56
+ <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
+
58
+
59
+ <p><pre class='syntax'>
60
+ <span class="ident">recorder</span> <span class="punct">=</span> <span class="constant">Message</span><span class="punct">::</span><span class="constant">Recorder</span><span class="punct">.</span><span class="ident">new</span>
61
+ <span class="ident">recorder</span><span class="punct">.</span><span class="ident">record</span><span class="punct">.</span><span class="ident">downcase</span>
62
+ <span class="ident">recorder</span><span class="punct">.</span><span class="ident">send_to</span><span class="punct">(&quot;</span><span class="string">HELLO</span><span class="punct">&quot;)</span> <span class="comment"># =&gt; [&quot;hello&quot;]</span>
63
+ <span class="ident">recorder</span><span class="punct">.</span><span class="ident">send_to</span><span class="punct">(&quot;</span><span class="string">WORLD</span><span class="punct">&quot;)</span> <span class="comment"># =&gt; [&quot;world&quot;]</span>
64
+ </pre></p>
65
+
66
+
67
+ <p>This is an example of branching. the <tt>with_results</tt> method accepts a block which is used to define multiple message chains at once.</p>
68
+
69
+
70
+ <p><pre class='syntax'>
71
+ <span class="ident">recorder</span> <span class="punct">=</span> <span class="constant">Message</span><span class="punct">::</span><span class="constant">Recorder</span><span class="punct">.</span><span class="ident">new</span>
72
+ <span class="ident">recorder</span><span class="punct">.</span><span class="ident">record</span><span class="punct">.</span><span class="ident">downcase</span><span class="punct">.</span><span class="ident">with_results</span> <span class="keyword">do</span>
73
+ <span class="ident">intern</span>
74
+ <span class="ident">capitalize</span>
75
+ <span class="keyword">end</span>
76
+
77
+ <span class="ident">recorder</span><span class="punct">.</span><span class="ident">send_to</span><span class="punct">(&quot;</span><span class="string">HELLO</span><span class="punct">&quot;)</span> <span class="comment"># =&gt; [:hello, &quot;Hello&quot;]</span>
78
+ </pre></p>
79
+
80
+
81
+ <h2>Demonstration of usage</h2>
82
+
83
+
84
+ <p>This is a more complex example with nested branches.</p>
85
+
86
+
87
+ <p><pre class='syntax'>
88
+ <span class="ident">recorder</span> <span class="punct">=</span> <span class="constant">Message</span><span class="punct">::</span><span class="constant">Recorder</span><span class="punct">.</span><span class="ident">new</span>
89
+ <span class="ident">recorder</span><span class="punct">.</span><span class="ident">record</span><span class="punct">.</span><span class="ident">compact</span><span class="punct">.</span><span class="ident">with_result</span> <span class="keyword">do</span>
90
+ <span class="ident">collect</span> <span class="punct">{</span> <span class="punct">|</span><span class="ident">s</span><span class="punct">|</span> <span class="ident">s</span><span class="punct">.</span><span class="ident">intern</span> <span class="punct">}</span>
91
+ <span class="ident">collect</span> <span class="punct">{</span> <span class="punct">|</span><span class="ident">s</span><span class="punct">|</span> <span class="ident">s</span><span class="punct">.</span><span class="ident">capitalize</span> <span class="punct">}.</span><span class="ident">with_results</span> <span class="keyword">do</span>
92
+ <span class="ident">collect</span> <span class="punct">{</span> <span class="punct">|</span><span class="ident">s</span><span class="punct">|</span> <span class="ident">s</span><span class="punct">.</span><span class="ident">concat</span> <span class="punct">&quot;</span><span class="string"> world</span><span class="punct">&quot;</span> <span class="punct">}</span>
93
+ <span class="ident">collect</span> <span class="punct">{</span> <span class="punct">|</span><span class="ident">s</span><span class="punct">|</span> <span class="ident">s</span><span class="punct">.</span><span class="ident">concat</span> <span class="punct">&quot;</span><span class="string"> simon</span><span class="punct">&quot;</span> <span class="punct">}</span>
94
+ <span class="keyword">end</span><span class="punct">.</span><span class="ident">with_results</span> <span class="keyword">do</span>
95
+ <span class="ident">collect</span> <span class="punct">{</span> <span class="punct">|</span><span class="ident">s</span><span class="punct">|</span> <span class="ident">s</span><span class="punct">.</span><span class="ident">concat</span> <span class="punct">&quot;</span><span class="string">!</span><span class="punct">&quot;</span> <span class="punct">}</span>
96
+ <span class="ident">collect</span> <span class="punct">{</span> <span class="punct">|</span><span class="ident">s</span><span class="punct">|</span> <span class="ident">s</span><span class="punct">.</span><span class="ident">concat</span> <span class="punct">&quot;</span><span class="string">?</span><span class="punct">&quot;</span> <span class="punct">}</span>
97
+ <span class="keyword">end</span>
98
+ <span class="keyword">end</span>
99
+
100
+ <span class="ident">results</span> <span class="punct">=</span> <span class="ident">recorder</span><span class="punct">.</span><span class="ident">send_to</span><span class="punct">([</span><span class="constant">nil</span><span class="punct">,</span> <span class="punct">&quot;</span><span class="string">hello</span><span class="punct">&quot;,</span> <span class="constant">nil</span><span class="punct">,</span> <span class="punct">&quot;</span><span class="string">bye</span><span class="punct">&quot;,</span> <span class="constant">nil</span><span class="punct">])</span>
101
+ <span class="ident">results</span> <span class="punct">==</span> <span class="punct">[</span> <span class="comment"># the result is ...</span>
102
+ <span class="punct">[</span><span class="symbol">:hello</span><span class="punct">,</span> <span class="symbol">:bye</span><span class="punct">],</span>
103
+ <span class="punct">[&quot;</span><span class="string">Hello world!</span><span class="punct">&quot;,</span> <span class="punct">&quot;</span><span class="string">Bye world!</span><span class="punct">&quot;],</span>
104
+ <span class="punct">[&quot;</span><span class="string">Hello simon!</span><span class="punct">&quot;,</span> <span class="punct">&quot;</span><span class="string">Bye simon!</span><span class="punct">&quot;],</span>
105
+ <span class="punct">[&quot;</span><span class="string">Hello world?</span><span class="punct">&quot;,</span> <span class="punct">&quot;</span><span class="string">Bye world?</span><span class="punct">&quot;],</span>
106
+ <span class="punct">[&quot;</span><span class="string">Hello simon?</span><span class="punct">&quot;,</span> <span class="punct">&quot;</span><span class="string">Bye simon?</span><span class="punct">&quot;]</span>
107
+ <span class="punct">]</span>
108
+ </pre></p>
109
+
110
+
111
+ <h2>License</h2>
112
+
113
+
114
+ <p>This code is free to use under the terms of the <span class="caps">MIT</span> license.</p>
115
+
116
+
117
+ <h2>Contact</h2>
118
+
119
+
120
+ <p>Comments are welcome. Send an email to <a href="mailto:simon@5xm.org">Simon Menke</a></p>
121
+ <p class="coda">
122
+ <a href="simon@5xm.org">Simon Menke</a>, 14th February 2008<br>
123
+ Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
124
+ </p>
125
+ </div>
126
+
127
+ <!-- insert site tracking codes here, like Google Urchin -->
128
+
129
+ </body>
130
+ </html>
@@ -0,0 +1,72 @@
1
+ h1. message recorder
2
+
3
+ h2. &#x2192; 'message-recorder'
4
+
5
+
6
+ h2. What
7
+
8
+ <tt>Message::Recorder</tt> is a tool to record messages send to Ruby objects.
9
+
10
+ h2. Installing
11
+
12
+ <pre syntax="ruby">sudo gem install message-recorder</pre>
13
+
14
+ h2. The basics
15
+
16
+ This snippet will first record a <tt>downcase</tt> message and after that it will replay the recorded messages on some objects.
17
+
18
+ <pre syntax="ruby">
19
+ recorder = Message::Recorder.new
20
+ recorder.record.downcase
21
+ recorder.send_to("HELLO") # => ["hello"]
22
+ recorder.send_to("WORLD") # => ["world"]
23
+ </pre>
24
+
25
+ This is an example of branching. the <tt>with_results</tt> method accepts a block which is used to define multiple message chains at once.
26
+
27
+ <pre syntax="ruby">
28
+ recorder = Message::Recorder.new
29
+ recorder.record.downcase.with_results do
30
+ intern
31
+ capitalize
32
+ end
33
+
34
+ recorder.send_to("HELLO") # => [:hello, "Hello"]
35
+ </pre>
36
+
37
+ h2. Demonstration of usage
38
+
39
+ This is a more complex example with nested branches.
40
+
41
+ <pre syntax="ruby">
42
+ recorder = Message::Recorder.new
43
+ recorder.record.compact.with_result do
44
+ collect { |s| s.intern }
45
+ collect { |s| s.capitalize }.with_results do
46
+ collect { |s| s.concat " world" }
47
+ collect { |s| s.concat " simon" }
48
+ end.with_results do
49
+ collect { |s| s.concat "!" }
50
+ collect { |s| s.concat "?" }
51
+ end
52
+ end
53
+
54
+ results = recorder.send_to([nil, "hello", nil, "bye", nil])
55
+ results == [ # the result is ...
56
+ [:hello, :bye],
57
+ ["Hello world!", "Bye world!"],
58
+ ["Hello simon!", "Bye simon!"],
59
+ ["Hello world?", "Bye world?"],
60
+ ["Hello simon?", "Bye simon?"]
61
+ ]
62
+ </pre>
63
+
64
+
65
+ h2. License
66
+
67
+ This code is free to use under the terms of the MIT license.
68
+
69
+ h2. Contact
70
+
71
+ Comments are welcome. Send an email to "Simon Menke":mailto:simon@5xm.org
72
+