paramix 2.0.0 → 2.0.1

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/.ruby ADDED
@@ -0,0 +1,42 @@
1
+ ---
2
+ source:
3
+ - PROFILE
4
+ authors:
5
+ - name: Thomas Sawyer
6
+ email: transfire@gmail.com
7
+ copyrights:
8
+ - holder: Thomas Sawyer
9
+ year: '2006'
10
+ license: BSD-2-Clause
11
+ replacements: []
12
+ alternatives: []
13
+ requirements:
14
+ - name: detroit
15
+ groups:
16
+ - build
17
+ development: true
18
+ - name: qed
19
+ groups:
20
+ - test
21
+ development: true
22
+ dependencies: []
23
+ conflicts: []
24
+ repositories:
25
+ - uri: git://github.com/rubyworks/paramix.git
26
+ scm: git
27
+ name: upstream
28
+ resources:
29
+ home: http://rubyworks.github.com/paramix
30
+ code: http://github.com/rubyworks/paramix
31
+ extra: {}
32
+ load_path:
33
+ - lib
34
+ revision: 0
35
+ title: Paramix
36
+ summary: Parametric Mixins
37
+ description: Parametric Mixins provides parameters for mixin modules.
38
+ organization: RubyWorks
39
+ created: '2006-01-01'
40
+ name: paramix
41
+ version: 2.0.1
42
+ date: '2011-10-22'
@@ -0,0 +1,6 @@
1
+ --protected
2
+ --private
3
+ lib
4
+ -
5
+ [A-Z]*.*
6
+
@@ -0,0 +1,31 @@
1
+ = COPYRIGHT NOTICES
2
+
3
+ == Paramix
4
+
5
+ Copyright:: (c) 2006 Thomas Sawyer, Rubyworks
6
+ License:: BSD-2-Clause
7
+ Website:: http://rubyworks.github.com/paramix
8
+
9
+ Copyright 2006 Thomas Sawyer. All rights reserved.
10
+
11
+ Redistribution and use in source and binary forms, with or without
12
+ modification, are permitted provided that the following conditions are met:
13
+
14
+ 1. Redistributions of source code must retain the above copyright notice,
15
+ this list of conditions and the following disclaimer.
16
+
17
+ 2. Redistributions in binary form must reproduce the above copyright
18
+ notice, this list of conditions and the following disclaimer in the
19
+ documentation and/or other materials provided with the distribution.
20
+
21
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
23
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24
+ COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
28
+ OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+
@@ -1,13 +1,24 @@
1
1
  = RELEASE HISTORY
2
2
 
3
+ == 2.0.1 // 2011-10-22
4
+
5
+ This release simply brings the project uptodate with the latest
6
+ build tools, and switches the license to BSD-2-Clause.
7
+
8
+ Changes:
9
+
10
+ * Modernize build configuration.
11
+ * Switch to FreeBSD license.
12
+
13
+
3
14
  == 2.0.0 // 2010-04-06
4
15
 
5
- Thanks to a conversation with Jonathan ... Paramix has been
6
- completely rewritten. Whereas anonymous modules were avoided
7
- in prior versions, it has become clear that the worries of
8
- memory consumption that would accompany them were largely
16
+ Thanks to a conversation with Jonathan Rochkind, Paramix has
17
+ been completely rewritten. Whereas anonymous modules were
18
+ avoided in prior versions, it has become clear that the worries
19
+ of memory consumption that would accompany them were largely
9
20
  unfounded. This new version therefore makes use of them.
10
- The new code is refreshing concise, and the design fully
21
+ The new code is refreshingly concise, and the design fully
11
22
  comforming to POLS.
12
23
 
13
24
  Changes:
@@ -0,0 +1,206 @@
1
+ = Basic Example
2
+
3
+ Require the library.
4
+
5
+ require 'paramix'
6
+
7
+ Create a parametric mixin.
8
+
9
+ module MyMixin
10
+ include Paramix::Parametric
11
+
12
+ parameterized do |params|
13
+
14
+ public params[:name] do
15
+ params[:value]
16
+ end
17
+
18
+ end
19
+ end
20
+
21
+ Create a class that uses the mixin and set the parameter.
22
+
23
+ class X
24
+ include MyMixin[:name => 'f', :value=>1]
25
+ end
26
+
27
+ Then the parameter is accessible.
28
+
29
+ X.new.f.assert == 1
30
+
31
+
32
+ = Nested Parematric Mixins
33
+
34
+ If we create another parametric mixin which depends on the first.
35
+
36
+ module AnotherMixin
37
+ include Paramix::Parametric
38
+ include MyMixin[:name => 'f', :value=>1]
39
+
40
+ parameterized do |params|
41
+
42
+ public params[:name] do
43
+ params[:value]
44
+ end
45
+
46
+ end
47
+ end
48
+
49
+ And a class for it.
50
+
51
+ class Y
52
+ include AnotherMixin[:name => 'g', :value=>2]
53
+ end
54
+
55
+ We can see that the parameters stay with their respective mixins.
56
+
57
+ Y.new.f.assert == 1
58
+ Y.new.g.assert == 2
59
+
60
+ However if we do the same, but do not paramterize the first module then
61
+ the including module also become parametric.
62
+
63
+ module ThirdMixin
64
+ #include Paramix::Parametric
65
+ include MyMixin
66
+
67
+ parameterized do |params|
68
+
69
+ public params[:name].succ do
70
+ params[:value]
71
+ end
72
+
73
+ end
74
+ end
75
+
76
+ And a class for it.
77
+
78
+ class Z
79
+ include ThirdMixin[:name => 'q', :value=>3]
80
+ end
81
+
82
+ We can see that the value of the parameter has propogated up to its
83
+ ancestor parametric module.
84
+
85
+ Z.new.q.assert == 3
86
+ Z.new.r.assert == 3
87
+
88
+
89
+ = Parametric Include
90
+
91
+ Load the library.
92
+
93
+ require 'paramix'
94
+
95
+ Given a parametric mixin.
96
+
97
+ module M
98
+ include Paramix::Parametric
99
+
100
+ parameterized do |params|
101
+
102
+ public :f do
103
+ params[:p]
104
+ end
105
+
106
+ end
107
+ end
108
+
109
+ We can inlcude the parameteric module in a some classes.
110
+
111
+ class I1
112
+ include M[:p => "mosh"]
113
+ end
114
+
115
+ class I2
116
+ include M[:p => "many"]
117
+ end
118
+
119
+ And the result will vary according to the parameter set.
120
+
121
+ I1.new.f #=> "mosh"
122
+ I2.new.f #=> "many"
123
+
124
+
125
+ = Parametric Extension
126
+
127
+ We can also extend classes witht the mixin.
128
+
129
+ class E1
130
+ extend M[:p => "mosh2"]
131
+ end
132
+
133
+ class E2
134
+ extend M[:p => "many2"]
135
+ end
136
+
137
+ And the results will likewise work as expected.
138
+
139
+ E1.f #=> "mosh2"
140
+ E2.f #=> "many2"
141
+
142
+
143
+ = Dynamically Defined Methods
144
+
145
+ Parametric mixins can be used to define dynamic code.
146
+
147
+ module N
148
+ include Paramix::Parametric
149
+
150
+ parameterized do |params|
151
+ attr_accessor params[:a]
152
+ end
153
+ end
154
+
155
+ Now if we include this module we will have new attributes based on
156
+ the parameter assigned.
157
+
158
+ class D1
159
+ include N[:a => "m1"]
160
+ end
161
+
162
+ class D2
163
+ include N[:a => "m2"]
164
+ end
165
+
166
+ d1 = D1.new
167
+ d1.m1 = :yes1
168
+
169
+ d1.m1 #=> :yes1
170
+
171
+ d2 = D2.new
172
+ d2.m2 = :yes2
173
+
174
+ d2.m2 #=> :yes2
175
+
176
+
177
+ = Works with Namespaces
178
+
179
+ Parametric mixins work regardless of the namespace depth.
180
+
181
+ module R
182
+ module M
183
+ include Paramix::Parametric
184
+
185
+ parameterized do |params|
186
+ public :f do
187
+ params[:p]
188
+ end
189
+ end
190
+ end
191
+ end
192
+
193
+ module Q
194
+ class I
195
+ include R::M[:p => "mosh"]
196
+ end
197
+ class E
198
+ extend R::M[:p => "many"]
199
+ end
200
+ end
201
+
202
+ Q::I.new.f #=> "mosh"
203
+
204
+ Q::E.f #=> "many"
205
+
206
+
@@ -0,0 +1,53 @@
1
+ # Paramix
2
+
3
+ | Project | Paramix |
4
+ |:-----------|:------------------------------------|
5
+ | Copyright | (c) 2006 Rubyworks |
6
+ | License | BSD-2-Clause |
7
+ | Website | http://rubyworks.github.com/paramix |
8
+ | GitHub | http://github.com/rubyworks/paramix |
9
+ | Status | [![Build Status](https://secure.travis-ci.org/rubyworks/paramix.png)](http://travis-ci.org/rubyworks/paramix) |
10
+
11
+ ## Description
12
+
13
+ Parametric Mixins provides an easy means to "functionalize" modules.
14
+ The module can then be differentiated upon usage according to the
15
+ parameters provided.
16
+
17
+
18
+ ## Release Notes
19
+
20
+ Please see the HISTORY.rdoc file.
21
+
22
+
23
+ ## Example
24
+
25
+ Here is a simple example that uses a a parameter
26
+ to define a method and another parameter to define
27
+ it's return value.
28
+
29
+ module M
30
+ include Paramix::Parametric
31
+
32
+ paramaterized do |params|
33
+ define_method params[:name] do
34
+ params[:value]
35
+ end
36
+ end
37
+ end
38
+
39
+ class X
40
+ include M[:name=>'foo', :value='bar']
41
+ end
42
+
43
+ X.new.foo #=> 'bar'
44
+
45
+
46
+ ## Copyrights
47
+
48
+ Copyright (c) 2006 Thomas Sawyer
49
+
50
+ This program is ditributed unser the terms of the BSD-2-Clause license.
51
+
52
+ See COPYING.rdoc file for details.
53
+
@@ -1,6 +1,10 @@
1
- # paramix.rb, Copyright (c)2010 Thomas Sawyer [MIT License]
1
+ # Paramix
2
+ # Copyright 2010 Thomas Sawyer
3
+ # Apache 2.0 License
2
4
 
3
- # Paramix project namespace.
5
+ require 'paramix/version'
6
+
7
+ # Paramix namespace.
4
8
  #
5
9
  module Paramix
6
10
 
@@ -27,7 +31,6 @@ module Paramix
27
31
  #
28
32
  # MyClass.new.hello #=> 'Hello from Ruby!'
29
33
  #
30
- #
31
34
  module Parametric
32
35
 
33
36
  #
@@ -0,0 +1,3 @@
1
+ module Paramix
2
+ VERSION = "2.0.0" #:erb: VERSION = "<%= version %>"
3
+ end
@@ -0,0 +1,87 @@
1
+ = Basic Example
2
+
3
+ Require the library.
4
+
5
+ require 'paramix'
6
+
7
+ Create a parametric mixin.
8
+
9
+ module MyMixin
10
+ include Paramix::Parametric
11
+
12
+ parameterized do |params|
13
+
14
+ public params[:name] do
15
+ params[:value]
16
+ end
17
+
18
+ end
19
+ end
20
+
21
+ Create a class that uses the mixin and set the parameter.
22
+
23
+ class X
24
+ include MyMixin[:name => 'f', :value=>1]
25
+ end
26
+
27
+ Then the parameter is accessible.
28
+
29
+ X.new.f.assert == 1
30
+
31
+
32
+ = Nested Parematric Mixins
33
+
34
+ If we create another parametric mixin which depends on the first.
35
+
36
+ module AnotherMixin
37
+ include Paramix::Parametric
38
+ include MyMixin[:name => 'f', :value=>1]
39
+
40
+ parameterized do |params|
41
+
42
+ public params[:name] do
43
+ params[:value]
44
+ end
45
+
46
+ end
47
+ end
48
+
49
+ And a class for it.
50
+
51
+ class Y
52
+ include AnotherMixin[:name => 'g', :value=>2]
53
+ end
54
+
55
+ We can see that the parameters stay with their respective mixins.
56
+
57
+ Y.new.f.assert == 1
58
+ Y.new.g.assert == 2
59
+
60
+ However if we do the same, but do not paramterize the first module then
61
+ the including module also become parametric.
62
+
63
+ module ThirdMixin
64
+ #include Paramix::Parametric
65
+ include MyMixin
66
+
67
+ parameterized do |params|
68
+
69
+ public params[:name].succ do
70
+ params[:value]
71
+ end
72
+
73
+ end
74
+ end
75
+
76
+ And a class for it.
77
+
78
+ class Z
79
+ include ThirdMixin[:name => 'q', :value=>3]
80
+ end
81
+
82
+ We can see that the value of the parameter has propogated up to its
83
+ ancestor parametric module.
84
+
85
+ Z.new.q.assert == 3
86
+ Z.new.r.assert == 3
87
+