contextr 0.0.1 → 0.0.2

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.
@@ -1,165 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
- class UnitContextRFoo
4
- layer :pre, :post, :wrap
5
- layer :stop_wrap, :stop_pre, :stop_post
6
- layer :order_wrap, :order_pre, :order_post
7
- layer :group_pre, :group_post
8
-
9
- def bar( sum )
10
- sum + 0b00100
11
- end
12
-
13
- pre.pre :bar do | nature |
14
- nature.arguments[ 0 ] += 0b00010
15
- end
16
-
17
- post.post :bar do | nature |
18
- nature.return_value += 0b01000
19
- end
20
-
21
- wrap.wrap :bar do | nature |
22
- nature.arguments[ 0 ] += 0b00001
23
- nature.call_next
24
- nature.return_value += 0b10000
25
- end
26
-
27
- stop_pre.pre :bar do | nature |
28
- nature.break! nature.arguments[0]
29
- end
30
- stop_wrap.wrap :bar do | nature |
31
- nature.break! nature.arguments[0]
32
- end
33
- stop_post.post :bar do | nature |
34
- nature.break! nature.return_value
35
- end
36
-
37
- order_pre.pre :bar do | nature |
38
- nature.break! :pre
39
- end
40
-
41
- order_post.post :bar do | nature |
42
- nature.break! :post
43
- end
44
-
45
- order_wrap.wrap :bar do | nature |
46
- nature.break! :wrap
47
- end
48
-
49
- group_pre.pre :bar do | nature |
50
- nature.return_value = :pre
51
- end
52
-
53
- group_pre.pre :bar do | nature |
54
- nature.break! nature.return_value
55
- end
56
-
57
- group_post.post :bar do | nature |
58
- nature.return_value = :post
59
- end
60
-
61
- group_post.post :bar do | nature |
62
- nature.break! nature.return_value
63
- end
64
- end
65
-
66
-
67
3
  class ContextRTest < Test::Unit::TestCase
68
- def setup
69
- @foo = UnitContextRFoo.new
70
- end
71
-
72
- def test_01_layer_activiation
73
- assert_equal 0b00100, @foo.bar( 0 )
74
-
75
- ContextR.with_layers :wrap do
76
- assert_equal 0b10101, @foo.bar( 0 )
77
-
78
- ContextR.without_layers :wrap do
79
- assert_equal 0b00100, @foo.bar( 0 )
80
- end
81
-
82
- assert_equal 0b10101, @foo.bar( 0 )
83
- end
84
-
85
- assert_equal 0b00100, @foo.bar( 0 )
86
- end
87
-
88
- def test_02_cascading_layers
89
- assert_equal 0b00100, @foo.bar( 0 )
90
-
91
- ContextR.with_layers :pre do
92
- assert_equal 0b00110, @foo.bar( 0 )
93
-
94
- ContextR.with_layers :post do
95
- assert_equal 0b01110, @foo.bar( 0 )
96
-
97
- ContextR.with_layers :wrap do
98
- assert_equal 0b11111, @foo.bar( 0 )
99
- end
100
-
101
- assert_equal 0b01110, @foo.bar( 0 )
102
- end
103
-
104
- assert_equal 0b00110, @foo.bar( 0 )
105
- end
106
-
107
- assert_equal 0b00100, @foo.bar( 0 )
108
- end
109
-
110
- def test_03_breaking_behaviour
111
- ContextR.with_layers :pre, :post, :stop_wrap do
112
- assert_equal 0b00010, @foo.bar( 0 )
113
- end
114
- end
115
-
116
- def test_04_ordering_by_selectors
117
- # pre before post
118
- ContextR.with_layers :order_pre, :order_post do
119
- assert_equal :pre, @foo.bar( 0 )
120
- end
121
- # pre before wrap
122
- ContextR.with_layers :order_wrap, :order_pre do
123
- assert_equal :pre, @foo.bar( 0 )
124
- end
125
- # wrap before body
126
- ContextR.with_layers :order_wrap do
127
- assert_equal :wrap, @foo.bar( 0 )
128
- end
129
- # wrap before post
130
- ContextR.with_layers :order_wrap, :order_post do
131
- assert_equal :wrap, @foo.bar( 0 )
132
- end
133
- # To be completed...
134
- end
135
-
136
- def test_05_ordering_by_layers
137
- ContextR.with_layers :wrap, :stop_wrap do
138
- assert_equal 0b00000, @foo.bar( 0 )
139
- end
140
- ContextR.with_layers :stop_wrap, :wrap do
141
- assert_equal 0b00001, @foo.bar( 0 )
142
- end
143
- ContextR.with_layers :pre, :stop_pre do
144
- assert_equal 0b00000, @foo.bar( 0 )
145
- end
146
- ContextR.with_layers :stop_pre, :pre do
147
- assert_equal 0b00010, @foo.bar( 0 )
148
- end
149
- ContextR.with_layers :post, :stop_post do
150
- assert_equal 0b01100, @foo.bar( 0 )
151
- end
152
- ContextR.with_layers :stop_post, :post do
153
- assert_equal 0b00100, @foo.bar( 0 )
154
- end
155
- end
156
-
157
- def test_06_ordering_within_groups
158
- ContextR.with_layers :group_pre do
159
- assert_equal nil, @foo.bar( 0 )
160
- end
161
- ContextR.with_layers :group_post do
162
- assert_equal :post, @foo.bar( 0 )
163
- end
4
+ def test_truth
5
+ assert true
164
6
  end
165
7
  end
@@ -68,6 +68,9 @@ require 'contextr'</pre>
68
68
 
69
69
 
70
70
  <pre syntax="ruby">
71
+ require "rubygems"
72
+ require "contextr"
73
+
71
74
  class Person
72
75
  attr_accessor :name, :address, :university
73
76
 
@@ -118,31 +121,36 @@ end
118
121
  hpi = University.new( "Hasso-Plattner-Institut", "Potsdam" )
119
122
  somePerson = Person.new( "Gregor Schmidt", "Berlin", hpi )
120
123
 
124
+ puts
121
125
  puts somePerson
122
- ContextR::with_layers :address do
126
+ ContextR::with_layers :education do
127
+ puts
123
128
  puts somePerson
124
129
 
125
- ContextR::with_layers :education do
130
+ ContextR::with_layers :address do
131
+ puts
126
132
  puts somePerson
127
133
 
128
- ContextR::without_layers :address do
134
+ ContextR::without_layers :education do
135
+ puts
129
136
  puts somePerson
130
137
  end
131
138
  end
132
139
  end
140
+ puts
133
141
  </pre>
134
142
  The above code prints:
135
143
 
136
144
  <pre>
137
145
  Name: Gregor Schmidt
138
146
 
139
- Name: Gregor Schmidt; Address: Berlin
147
+ Name: Gregor Schmidt;
148
+ [Education] Name: Hasso-Plattner-Institut
140
149
 
141
150
  Name: Gregor Schmidt; Address: Berlin;
142
151
  [Education] Name: Hasso-Plattner-Institut; Address: Potsdam
143
152
 
144
- Name: Gregor Schmidt;
145
- [Education] Name: Hasso-Plattner-Institut
153
+ Name: Gregor Schmidt; Address: Berlin
146
154
  </pre>
147
155
 
148
156
  <p>You may find other examples in the <code>examples</code> folder.</p>
@@ -154,7 +162,7 @@ Name: Gregor Schmidt;
154
162
  <ul>
155
163
  <li><a href="http://rubyforge.org/projects/contextr">Rubyforge Project Page</a></li>
156
164
  <li><a href="http://www.nach-vorne.de">Author&#8217;s Development Blog &#8211; The Ruby Ahead</a></li>
157
- <li><a href="http://www.ohloh.net/projects/5037">Ohloh Statistics on ContextR</a></li>
165
+ <li><a href="http://www.ohloh.net/projects/5037">ContextR Statistics on ohloh</a></li>
158
166
  </ul>
159
167
 
160
168
 
@@ -169,7 +177,7 @@ Name: Gregor Schmidt;
169
177
 
170
178
  <p>Comments are welcome. Send an email to <a href="mailto:ruby@schmidtwisser.de">Gregor Schmidt</a></p>
171
179
  <p class="coda">
172
- <a href="mailto:drnicwilliams@gmail.com">Dr Nic</a>, 8th May 2007<br>
180
+ <a href="mailto:drnicwilliams@gmail.com">Dr Nic</a>, 9th May 2007<br>
173
181
  Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
174
182
  </p>
175
183
  </div>
@@ -25,6 +25,9 @@ and ContextR will be ready to use.
25
25
  h2. Demonstration of usage
26
26
 
27
27
  <pre syntax="ruby">
28
+ require "rubygems"
29
+ require "contextr"
30
+
28
31
  class Person
29
32
  attr_accessor :name, :address, :university
30
33
 
@@ -72,34 +75,40 @@ class University
72
75
  end
73
76
  end
74
77
 
78
+
75
79
  hpi = University.new( "Hasso-Plattner-Institut", "Potsdam" )
76
80
  somePerson = Person.new( "Gregor Schmidt", "Berlin", hpi )
77
81
 
82
+ puts
78
83
  puts somePerson
79
- ContextR::with_layers :address do
84
+ ContextR::with_layers :education do
85
+ puts
80
86
  puts somePerson
81
87
 
82
- ContextR::with_layers :education do
88
+ ContextR::with_layers :address do
89
+ puts
83
90
  puts somePerson
84
91
 
85
- ContextR::without_layers :address do
92
+ ContextR::without_layers :education do
93
+ puts
86
94
  puts somePerson
87
95
  end
88
96
  end
89
97
  end
98
+ puts
90
99
  </pre>
91
100
  The above code prints:
92
101
 
93
102
  <pre>
94
103
  Name: Gregor Schmidt
95
104
 
96
- Name: Gregor Schmidt; Address: Berlin
105
+ Name: Gregor Schmidt;
106
+ [Education] Name: Hasso-Plattner-Institut
97
107
 
98
108
  Name: Gregor Schmidt; Address: Berlin;
99
109
  [Education] Name: Hasso-Plattner-Institut; Address: Potsdam
100
110
 
101
- Name: Gregor Schmidt;
102
- [Education] Name: Hasso-Plattner-Institut
111
+ Name: Gregor Schmidt; Address: Berlin
103
112
  </pre>
104
113
 
105
114
  You may find other examples in the <code>examples</code> folder.
@@ -108,7 +117,7 @@ h2. Other resources
108
117
 
109
118
  * "Rubyforge Project Page":http://rubyforge.org/projects/contextr
110
119
  * "Author's Development Blog - The Ruby Ahead":http://www.nach-vorne.de
111
- * "Ohloh Statistics on ContextR":http://www.ohloh.net/projects/5037
120
+ * "ContextR Statistics on ohloh":http://www.ohloh.net/projects/5037
112
121
 
113
122
  h2. License
114
123
 
metadata CHANGED
@@ -3,12 +3,11 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: contextr
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.1
7
- date: 2007-05-08 00:00:00 +02:00
6
+ version: 0.0.2
7
+ date: 2007-05-10 00:00:00 +02:00
8
8
  summary: The goal is to equip Ruby with an API to allow context-oriented programming.
9
9
  require_paths:
10
10
  - lib
11
- - ext
12
11
  email: ruby@schmidtwisser.de
13
12
  homepage: http://contextr.rubyforge.org
14
13
  rubyforge_project: contextr
@@ -38,19 +37,21 @@ files:
38
37
  - Rakefile
39
38
  - examples/education.rb
40
39
  - examples/fibonacci.rb
41
- - ext/dynamic.rb
42
- - ext/method_nature.rb
43
40
  - lib/contextr.rb
44
41
  - lib/contextr/contextr.rb
42
+ - lib/contextr/layer.rb
45
43
  - lib/contextr/version.rb
46
44
  - lib/core_ext/class.rb
47
45
  - lib/core_ext/module.rb
48
46
  - lib/core_ext/proc.rb
47
+ - lib/ext/dynamic.rb
48
+ - lib/ext/method_nature.rb
49
49
  - rake/group_spec_task.rb
50
50
  - rake/specific_group_spec_task.rb
51
51
  - scripts/txt2html
52
52
  - setup.rb
53
53
  - spec/contextr/contextr_api_spec.rb
54
+ - spec/contextr/contextr_functional_spec.rb
54
55
  - spec/core_ext/module_spec.rb
55
56
  - spec/core_ext/proc_spec.rb
56
57
  - spec/spec_helper.rb
@@ -1,17 +0,0 @@
1
- unless Object.const_defined? "MethodNatureSuperClass"
2
- MethodNatureSuperClass = Struct.new(:arguments, :return_value, :break, :block)
3
- end
4
- class MethodNature < MethodNatureSuperClass
5
- def break!( *value )
6
- self.break = true
7
- self.return_value = value.first unless value.empty?
8
- end
9
-
10
- def call_next
11
- block.call( *arguments )
12
- end
13
-
14
- def call_next_with( *args )
15
- block.call( *args )
16
- end
17
- end