paramix 1.0.1 → 1.1.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/HISTORY +24 -2
- data/lib/paramix.rb +111 -122
- data/meta/version +1 -1
- data/test/nested/test_nested_both.rb +44 -0
- data/test/nested/test_nested_bottom.rb +51 -0
- data/test/nested/test_nested_top.rb +47 -0
- data/test/test_paramix_callback.rb +28 -25
- data/test/test_paramix_extend.rb +35 -0
- data/test/test_paramix_include.rb +35 -0
- data/test/test_paramix_inject.rb +6 -53
- data/test/test_paramix_namespace.rb +15 -16
- metadata +13 -6
- data/Syckfile +0 -79
- data/test/test_paramix_basic.rb +0 -36
data/HISTORY
CHANGED
@@ -1,5 +1,26 @@
|
|
1
1
|
= RELEASE HISTORY
|
2
2
|
|
3
|
+
== 1.1.0 // 2010-04-05
|
4
|
+
|
5
|
+
The previous versions did not properly support nested parametric
|
6
|
+
includes, i.e. including one parametirc mixin into another. This
|
7
|
+
release fixed this issue. However, to do so provided difficult
|
8
|
+
and required some changes to the API. In particular, instead
|
9
|
+
of +mixin_params[M][:p]+ one must now use +mixin_param(M,:p)+.
|
10
|
+
It was not longer possible to simply return a hash, since special
|
11
|
+
lookup logic is required to handle nested mixins. It should also
|
12
|
+
be noted that +Module#mixin_parameters+, which stores the actual
|
13
|
+
parameters is no longer accessible at the instance level, just
|
14
|
+
as +mixin_param()+ is soley an instance method (at the class level
|
15
|
+
it is used to access the singleton parameters).
|
16
|
+
|
17
|
+
Changes:
|
18
|
+
|
19
|
+
* Proper support for nested parametric mixins.
|
20
|
+
* Provide #mixin_param method to lookup parameters.
|
21
|
+
* The mixin_parameters method is class-level only.
|
22
|
+
|
23
|
+
|
3
24
|
== 1.0.1 // 2010-04-03
|
4
25
|
|
5
26
|
This release simply removed dependencies on Facets.
|
@@ -12,8 +33,9 @@ Changes:
|
|
12
33
|
|
13
34
|
== 1.0.0 // 2009-06-29
|
14
35
|
|
15
|
-
This is the initial stand-alone release of Paramix
|
16
|
-
|
36
|
+
This is the initial stand-alone release of Paramix spun-off
|
37
|
+
from Ruby Facets (and is actually he second major version, the
|
38
|
+
original being spun of from the Nitro/Og Glue library).
|
17
39
|
|
18
40
|
Changes:
|
19
41
|
|
data/lib/paramix.rb
CHANGED
@@ -1,43 +1,16 @@
|
|
1
|
-
# TITLE:
|
2
|
-
#
|
3
|
-
# Parametric Mixins
|
4
|
-
#
|
5
|
-
# SUMMARY:
|
6
|
-
#
|
7
|
-
# Parametric Mixins provides parameters for mixin modules.
|
8
|
-
#
|
9
|
-
# COPYRIGHT:
|
10
|
-
#
|
11
|
-
# Copyright (c) 2008 T. Sawyer
|
12
|
-
#
|
13
|
-
# LICENSE:
|
14
|
-
#
|
15
|
-
# Ruby License
|
16
|
-
#
|
17
|
-
# This module is free software. You may use, modify, and/or redistribute this
|
18
|
-
# software under the same terms as Ruby.
|
19
|
-
#
|
20
|
-
# This program is distributed in the hope that it will be useful, but WITHOUT
|
21
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
22
|
-
# FOR A PARTICULAR PURPOSE.
|
23
|
-
#
|
24
|
-
# AUTHORS:
|
25
|
-
#
|
26
|
-
# - Thomas Sawyer
|
27
|
-
|
28
|
-
|
29
1
|
# = Parametric Mixin
|
30
2
|
#
|
31
3
|
# Parametric Mixins provides parameters for mixin modules.
|
32
4
|
# Module parameters can be set at the time of inclusion
|
33
5
|
# or extension using Module#[] method, then parameters
|
34
|
-
# can be accessed via the #mixin_parameters
|
6
|
+
# can be accessed via the #mixin_param and #mixin_parameters
|
7
|
+
# methods.
|
35
8
|
#
|
36
9
|
# module MyMixin
|
37
10
|
# include Paramix
|
38
11
|
#
|
39
12
|
# def hello
|
40
|
-
# puts "Hello from #{
|
13
|
+
# puts "Hello from #{ mixin_param(MyMixin, :name) }!"
|
41
14
|
# end
|
42
15
|
# end
|
43
16
|
#
|
@@ -48,154 +21,170 @@
|
|
48
21
|
# m = MyClass.new
|
49
22
|
# m.hello #=> 'Hello from Ruby!'
|
50
23
|
#
|
51
|
-
# You can view the full set of parameters via the
|
52
|
-
# class method, which returns a hash keyed on the included modules.
|
24
|
+
# You can view the full set of parameters via the +mixin_parameters+ method.
|
53
25
|
#
|
54
|
-
# MyClass.mixin_parameters
|
55
|
-
# MyClass.mixin_parameters[MyMixin] #=> {:name=>'ruby'}
|
26
|
+
# MyClass.mixin_parameters #=> {MyMixin => {:name => 'ruby'}}
|
56
27
|
#
|
57
|
-
#
|
28
|
+
# Including Paramix into a module is essentially equivalent to defining
|
29
|
+
# a module method:
|
58
30
|
#
|
59
31
|
# def [](parameters)
|
60
|
-
# Paramix.new(self, parameters)
|
32
|
+
# Paramix::Proxy.new(self, parameters)
|
61
33
|
# end
|
62
34
|
#
|
63
|
-
# Paramix.new can also take a block that injects code into the
|
64
|
-
#
|
65
|
-
#
|
66
|
-
#
|
35
|
+
# Paramix::Proxy.new can also take a block that injects code into the
|
36
|
+
# mixin. This is useful as an alternative to using the #included
|
37
|
+
# callback for creating metaclass dynamics based on mixin parameters.
|
38
|
+
# For example:
|
67
39
|
#
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
40
|
+
# module MyMixin
|
41
|
+
# def self.[](parameters)
|
42
|
+
# Paramix::Mixin.new(self, parameters) do
|
43
|
+
# attr_accessor parameters[MyMixin][:name]
|
44
|
+
# end
|
71
45
|
# end
|
72
46
|
# end
|
73
47
|
#
|
74
48
|
# As opposed to:
|
75
49
|
#
|
76
|
-
# module
|
50
|
+
# module MyMixin
|
51
|
+
# include Paramix
|
52
|
+
#
|
77
53
|
# def self.included(base)
|
78
54
|
# base.class_eval do
|
79
|
-
# attr_accessor
|
55
|
+
# attr_accessor base.mixin_parameters[:name]
|
80
56
|
# end
|
57
|
+
# super(base)
|
81
58
|
# end
|
82
59
|
# end
|
83
60
|
#
|
84
|
-
|
85
|
-
# More conveniently a new callback has been added, #included_with_parameters,
|
86
|
-
# which passes in the parameters in addition to the base class/module.
|
87
|
-
#
|
88
|
-
# module Mixin
|
89
|
-
# def self.included_with_parameters( base, parms )
|
90
|
-
# base.class_eval {
|
91
|
-
# def hello
|
92
|
-
# puts "Hello from #{mixin_parameters[Mixin][:name]}"
|
93
|
-
# end
|
94
|
-
# }
|
95
|
-
# end
|
96
|
-
# end
|
97
|
-
#
|
98
|
-
# We would prefer to have passed the parameters through the #included callback
|
99
|
-
# method itself, but implementation of such a feature is much more complicated.
|
100
|
-
# If a reasonable solution presents itself in the future however, we will fix.
|
101
|
-
#++
|
102
|
-
|
103
|
-
module Paramix # or PatrametricMixin ?
|
61
|
+
module Paramix
|
104
62
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
# It you want to define the module's ::[] method by hand. You
|
114
|
-
# can use Paramix.new instead of Paramix::Delegator.new.
|
115
|
-
|
116
|
-
def self.new(delegate_module, parameters={}, &base_block)
|
117
|
-
Delegator.new(delegate_module, parameters, &base_block)
|
63
|
+
#
|
64
|
+
def self.included(base)
|
65
|
+
base.extend(ClassMethods)
|
66
|
+
super(base)
|
118
67
|
end
|
119
68
|
|
120
69
|
#
|
70
|
+
module ClassMethods
|
71
|
+
def [](parameters)
|
72
|
+
Proxy.new(self, parameters)
|
73
|
+
end
|
121
74
|
|
122
|
-
|
75
|
+
def included(base)
|
76
|
+
base.extend(ClassMethods)
|
77
|
+
super(base)
|
78
|
+
end
|
79
|
+
end
|
123
80
|
|
124
|
-
|
81
|
+
class Proxy < Module
|
82
|
+
attr :mixin
|
125
83
|
attr :parameters
|
126
|
-
attr :
|
84
|
+
attr :block
|
127
85
|
|
128
86
|
#
|
129
|
-
|
130
|
-
|
131
|
-
@
|
132
|
-
@
|
133
|
-
@base_block = base_block
|
87
|
+
def initialize(mixin, parameters, &block)
|
88
|
+
@mixin = mixin
|
89
|
+
@parameters = parameters || {}
|
90
|
+
@block = block
|
134
91
|
end
|
135
92
|
|
136
93
|
#
|
137
|
-
|
138
94
|
def append_features(base)
|
139
|
-
|
95
|
+
mixin = @mixin
|
140
96
|
|
141
|
-
base.
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
alias_method :mixin_params, :mixin_parameters
|
146
|
-
end
|
97
|
+
base.mixin_parameters[mixin] ||= {}
|
98
|
+
base.mixin_parameters[mixin].update(@parameters)
|
99
|
+
|
100
|
+
mixin.module_eval{ append_features(base) }
|
147
101
|
|
148
|
-
base.module_eval
|
102
|
+
base.module_eval{ include InstanceParameterize }
|
103
|
+
#base.extend ClassParameterize
|
149
104
|
|
150
|
-
|
105
|
+
mixin.module_eval{ included(base) }
|
106
|
+
|
107
|
+
base.module_eval(&@block) if @block
|
151
108
|
end
|
152
109
|
|
153
110
|
#
|
154
|
-
|
155
111
|
def extend_object(base)
|
156
|
-
|
112
|
+
mixin = @mixin
|
157
113
|
|
158
|
-
|
114
|
+
metabase = (class << base; self; end)
|
159
115
|
|
160
|
-
|
161
|
-
|
162
|
-
baseclass.mixin_parameters
|
163
|
-
end
|
164
|
-
alias_method :mixin_params, :mixin_parameters
|
165
|
-
end
|
116
|
+
metabase.mixin_parameters[mixin] ||= {}
|
117
|
+
metabase.mixin_parameters[mixin].update(@parameters)
|
166
118
|
|
167
|
-
|
119
|
+
mixin.module_eval{ extend_object(base) }
|
120
|
+
|
121
|
+
base.extend ClassParameterize
|
122
|
+
|
123
|
+
metabase.module_eval(&@block) if @block
|
124
|
+
end
|
168
125
|
|
169
|
-
|
126
|
+
#
|
127
|
+
module InstanceParameterize
|
128
|
+
#
|
129
|
+
def mixin_param(m, n)
|
130
|
+
h = {}; r = nil
|
131
|
+
self.class.ancestors.each do |a|
|
132
|
+
break if Paramix == a
|
133
|
+
break if m == a
|
134
|
+
q = a.mixin_parameters
|
135
|
+
#if q = Paramix.mixin_params[a]
|
136
|
+
if q[m] && q[m].key?(n)
|
137
|
+
r = q[m][n]
|
138
|
+
else
|
139
|
+
q.each do |k,v|
|
140
|
+
h.update(v)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
#end
|
144
|
+
end
|
145
|
+
r ? r : h[n]
|
146
|
+
end
|
170
147
|
end
|
171
148
|
|
172
|
-
|
173
|
-
|
149
|
+
#
|
150
|
+
module ClassParameterize
|
151
|
+
#
|
152
|
+
def mixin_param(m, n)
|
153
|
+
h = {}; r = nil
|
154
|
+
ancestors.each do |a|
|
155
|
+
break if Paramix==a
|
156
|
+
if q = a.meta_class.mixin_parameters #[class << a; self ; end]
|
157
|
+
#if q = Paramix.mixin_params[class << a; self ; end]
|
158
|
+
if q[m] && q[m].key?(n)
|
159
|
+
r = q[m][n]
|
160
|
+
else
|
161
|
+
q.each do |k,v|
|
162
|
+
h.update(v)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
r ? r : h[n]
|
168
|
+
end
|
174
169
|
end
|
175
170
|
|
176
171
|
end
|
177
172
|
|
178
173
|
end
|
179
174
|
|
180
|
-
|
175
|
+
#
|
181
176
|
class Module
|
182
177
|
|
183
|
-
# Store for parametric mixin parameters.
|
184
|
-
#
|
185
|
-
# Returns a hash, the keys of which are the parametric mixin module
|
186
|
-
# and the values are the parameters associacted with this module/class.
|
187
|
-
#
|
188
|
-
# class C
|
189
|
-
# include P(:x=>1)
|
190
|
-
# end
|
191
|
-
#
|
192
|
-
# C.mixin_parameters[P] #=> {:x=>1}
|
193
|
-
#
|
194
178
|
def mixin_parameters
|
195
|
-
@
|
179
|
+
@mixin_params ||= {}
|
196
180
|
end
|
197
181
|
|
198
182
|
alias_method :mixin_params, :mixin_parameters
|
199
183
|
|
200
184
|
end
|
201
185
|
|
186
|
+
module Kernel
|
187
|
+
def meta_class
|
188
|
+
(class << self; self; end)
|
189
|
+
end
|
190
|
+
end
|
data/meta/version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0
|
1
|
+
1.1.0
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'paramix'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TC_Paramix_Nested_Both < Test::Unit::TestCase
|
5
|
+
|
6
|
+
# -- fixture ------------------------------
|
7
|
+
|
8
|
+
module M
|
9
|
+
include Paramix
|
10
|
+
|
11
|
+
def f
|
12
|
+
mixin_param(M,:p)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module N
|
17
|
+
include Paramix
|
18
|
+
include M[:p=>"mood"]
|
19
|
+
|
20
|
+
def g
|
21
|
+
mixin_params(N,:p)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class I
|
26
|
+
include N[:p => "mosh"]
|
27
|
+
end
|
28
|
+
|
29
|
+
class E
|
30
|
+
extend N[:p => "many"]
|
31
|
+
end
|
32
|
+
|
33
|
+
# -- tests --------------------------------
|
34
|
+
|
35
|
+
def test_include
|
36
|
+
assert_equal( "mood", I.new.f )
|
37
|
+
end
|
38
|
+
|
39
|
+
#def test_extend
|
40
|
+
# assert_equal( "many", E.f )
|
41
|
+
#end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'paramix'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TC_Paramix_Nested_Bottom < Test::Unit::TestCase
|
5
|
+
|
6
|
+
# -- fixture ------------------------------
|
7
|
+
|
8
|
+
module M
|
9
|
+
include Paramix
|
10
|
+
|
11
|
+
def f
|
12
|
+
mixin_param(M,:p)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module N
|
17
|
+
include M
|
18
|
+
|
19
|
+
def g
|
20
|
+
mixin_param(N,:p)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class I
|
25
|
+
include N[:p => "mosh"]
|
26
|
+
end
|
27
|
+
|
28
|
+
class E
|
29
|
+
extend N[:p => "many"]
|
30
|
+
end
|
31
|
+
|
32
|
+
# -- tests --------------------------------
|
33
|
+
|
34
|
+
def test_include_f
|
35
|
+
assert_equal( "mosh", I.new.f )
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_include_g
|
39
|
+
assert_equal( "mosh", I.new.g )
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_extend_f
|
43
|
+
assert_equal( "many", E.f )
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_extend_g
|
47
|
+
assert_equal( "many", E.g )
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'paramix'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TC_Paramix_Nested_Top < Test::Unit::TestCase
|
5
|
+
|
6
|
+
# -- fixture ------------------------------
|
7
|
+
|
8
|
+
module M
|
9
|
+
include Paramix
|
10
|
+
|
11
|
+
def f
|
12
|
+
mixin_param(M,:p)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module N
|
17
|
+
include M[:p=>"mood"]
|
18
|
+
|
19
|
+
def g
|
20
|
+
mixin_param(N,:p)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class I
|
25
|
+
include N
|
26
|
+
end
|
27
|
+
|
28
|
+
class E
|
29
|
+
extend N
|
30
|
+
end
|
31
|
+
|
32
|
+
# -- tests --------------------------------
|
33
|
+
|
34
|
+
def test_include_f
|
35
|
+
assert_equal( "mood", I.new.f )
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_include_g
|
39
|
+
assert_equal( nil, I.new.g ) # TODO: or error ?
|
40
|
+
end
|
41
|
+
|
42
|
+
#def test_extend
|
43
|
+
# assert_equal( "many", E.f )
|
44
|
+
#end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
@@ -3,53 +3,56 @@ require 'test/unit'
|
|
3
3
|
|
4
4
|
class TC_Paramix_Callback < Test::Unit::TestCase
|
5
5
|
|
6
|
+
# -- fixture ------------------------------
|
7
|
+
|
6
8
|
module M
|
7
9
|
include Paramix
|
8
10
|
|
9
11
|
def f
|
10
|
-
|
12
|
+
mixin_param(M,:p)
|
11
13
|
end
|
12
14
|
|
15
|
+
#
|
13
16
|
def self.included(base)
|
14
|
-
params = base.mixin_params[self]
|
15
17
|
base.class_eval do
|
16
|
-
|
17
|
-
params
|
18
|
-
end
|
18
|
+
attr_accessor mixin_parameters[M][:p]
|
19
19
|
end
|
20
|
+
super(base)
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
23
|
-
class
|
24
|
-
include M[:p => "
|
24
|
+
class C1
|
25
|
+
include M[:p => "c1"]
|
25
26
|
end
|
26
27
|
|
27
|
-
class
|
28
|
-
include M[:p => "
|
28
|
+
class C2
|
29
|
+
include M[:p => "c2"]
|
29
30
|
end
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
# -- tests --------------------------------
|
33
|
+
|
34
|
+
def test_class_1
|
35
|
+
c = C1.new
|
36
|
+
#assert_equal( "c1", c.mixin_params[:p] )
|
37
|
+
assert_equal( "c1", c.f )
|
35
38
|
end
|
36
39
|
|
37
|
-
def
|
38
|
-
|
39
|
-
assert_equal( "
|
40
|
-
assert_equal( "
|
40
|
+
def test_class_2
|
41
|
+
c = C2.new
|
42
|
+
#assert_equal( "c2", c.mixin_params[:p] )
|
43
|
+
assert_equal( "c2", c.f )
|
41
44
|
end
|
42
45
|
|
43
|
-
def
|
44
|
-
|
45
|
-
|
46
|
+
def test_callback_class_1
|
47
|
+
c = C1.new
|
48
|
+
c.c1 = :yes1
|
49
|
+
assert_equal(:yes1, c.c1)
|
46
50
|
end
|
47
51
|
|
48
|
-
def
|
49
|
-
c =
|
50
|
-
|
51
|
-
|
52
|
-
assert_equal( {:p => "steak"}, d.check )
|
52
|
+
def test_callback_class_2
|
53
|
+
c = C2.new
|
54
|
+
c.c2 = :yes2
|
55
|
+
assert_equal(:yes2, c.c2)
|
53
56
|
end
|
54
57
|
|
55
58
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'paramix'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TC_Paramix_Extend < Test::Unit::TestCase
|
5
|
+
|
6
|
+
# -- fixture ------------------------------
|
7
|
+
|
8
|
+
module M
|
9
|
+
include Paramix
|
10
|
+
|
11
|
+
def f
|
12
|
+
mixin_param(M,:p)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class C1
|
17
|
+
extend M[:p => "mosh"]
|
18
|
+
end
|
19
|
+
|
20
|
+
class C2
|
21
|
+
extend M[:p => "many"]
|
22
|
+
end
|
23
|
+
|
24
|
+
# -- tests --------------------------------
|
25
|
+
|
26
|
+
def test_class_1
|
27
|
+
assert_equal( "mosh", C1.f )
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_class_2
|
31
|
+
assert_equal( "many", C2.f )
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'paramix'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TC_Paramix_Include < Test::Unit::TestCase
|
5
|
+
|
6
|
+
# -- fixture ------------------------------
|
7
|
+
|
8
|
+
module M
|
9
|
+
include Paramix
|
10
|
+
|
11
|
+
def f
|
12
|
+
mixin_param(M,:p)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class C1
|
17
|
+
include M[:p => "mosh"]
|
18
|
+
end
|
19
|
+
|
20
|
+
class C2
|
21
|
+
include M[:p => "many"]
|
22
|
+
end
|
23
|
+
|
24
|
+
# -- tests --------------------------------
|
25
|
+
|
26
|
+
def test_class_1
|
27
|
+
assert_equal( "mosh", C1.new.f )
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_class_2
|
31
|
+
assert_equal( "many", C2.new.f )
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
data/test/test_paramix_inject.rb
CHANGED
@@ -1,63 +1,14 @@
|
|
1
1
|
require 'paramix'
|
2
2
|
require 'test/unit'
|
3
3
|
|
4
|
-
class
|
4
|
+
class TC_Paramix_Inject < Test::Unit::TestCase
|
5
5
|
|
6
|
-
|
7
|
-
# Manually define Paramix method.
|
8
|
-
def self.[](parameters)
|
9
|
-
Paramix.new(self, parameters) do
|
10
|
-
define_method :check do
|
11
|
-
mixin_params[M] # or parameters
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def f
|
17
|
-
mixin_params[M][:p]
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
class C
|
22
|
-
include M[:p => "check"]
|
23
|
-
end
|
24
|
-
|
25
|
-
class D
|
26
|
-
include M[:p => "steak"]
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_02_001
|
30
|
-
c = C.new
|
31
|
-
assert_equal( "check", c.mixin_params[M][:p] )
|
32
|
-
assert_equal( "check", c.f )
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_02_002
|
36
|
-
d = D.new
|
37
|
-
assert_equal( "steak", d.mixin_params[M][:p] )
|
38
|
-
assert_equal( "steak", d.f )
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_02_003
|
42
|
-
assert_equal( {M=>{:p => "check"}}, C.mixin_parameters )
|
43
|
-
assert_equal( {M=>{:p => "steak"}}, D.mixin_parameters )
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_02_004
|
47
|
-
c = C.new
|
48
|
-
assert_equal( {:p => "check"}, c.check )
|
49
|
-
d = D.new
|
50
|
-
assert_equal( {:p => "steak"}, d.check )
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
class TC_Paramix_04 < Test::Unit::TestCase
|
6
|
+
# -- fixture ------------------------------
|
56
7
|
|
57
8
|
module O
|
58
9
|
def self.[](parameters)
|
59
|
-
Paramix.new(self, parameters) do
|
60
|
-
attr_accessor mixin_parameters[O][:name]
|
10
|
+
Paramix::Proxy.new(self, parameters) do
|
11
|
+
attr_accessor mixin_parameters[O][:name] #mixin_params(O, :name)
|
61
12
|
end
|
62
13
|
end
|
63
14
|
end
|
@@ -66,6 +17,8 @@ class TC_Paramix_04 < Test::Unit::TestCase
|
|
66
17
|
include O[:name=>"x"]
|
67
18
|
end
|
68
19
|
|
20
|
+
# -- tests --------------------------------
|
21
|
+
|
69
22
|
def test_attribute
|
70
23
|
o = X.new
|
71
24
|
assert_nothing_raised{ o.x = 10 }
|
@@ -1,39 +1,38 @@
|
|
1
1
|
require 'paramix'
|
2
2
|
require 'test/unit'
|
3
3
|
|
4
|
-
class
|
4
|
+
class TC_Paramix_Namespace < Test::Unit::TestCase
|
5
5
|
|
6
|
-
|
6
|
+
# -- fixture ------------------------------
|
7
|
+
|
8
|
+
module N1
|
7
9
|
module M
|
8
10
|
include Paramix
|
9
11
|
|
10
12
|
def f
|
11
|
-
|
13
|
+
mixin_param(M,:p)
|
12
14
|
end
|
13
15
|
end
|
14
16
|
end
|
15
17
|
|
16
|
-
module
|
17
|
-
class
|
18
|
-
|
18
|
+
module N2
|
19
|
+
class I
|
20
|
+
include N1::M[:p => "mosh"]
|
19
21
|
end
|
20
22
|
|
21
|
-
class
|
22
|
-
extend
|
23
|
+
class E
|
24
|
+
extend N1::M[:p => "many"]
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
26
|
-
|
27
|
-
assert_equal( "mosh", Q2::C.f )
|
28
|
-
end
|
28
|
+
# -- tests --------------------------------
|
29
29
|
|
30
|
-
def
|
31
|
-
assert_equal( "
|
30
|
+
def test_class_1
|
31
|
+
assert_equal( "mosh", N2::I.new.f )
|
32
32
|
end
|
33
33
|
|
34
|
-
def
|
35
|
-
assert_equal(
|
36
|
-
assert_equal( {Q1::M=>{:p => "many"}}, (class << Q2::D; self; end).mixin_parameters )
|
34
|
+
def test_class_2
|
35
|
+
assert_equal( "many", N2::E.f )
|
37
36
|
end
|
38
37
|
|
39
38
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 1
|
7
|
-
- 0
|
8
7
|
- 1
|
9
|
-
|
8
|
+
- 0
|
9
|
+
version: 1.1.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Thomas Sawyer
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-05 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -42,14 +42,17 @@ files:
|
|
42
42
|
- meta/summary
|
43
43
|
- meta/title
|
44
44
|
- meta/version
|
45
|
-
- test/
|
45
|
+
- test/nested/test_nested_both.rb
|
46
|
+
- test/nested/test_nested_bottom.rb
|
47
|
+
- test/nested/test_nested_top.rb
|
46
48
|
- test/test_paramix_callback.rb
|
49
|
+
- test/test_paramix_extend.rb
|
50
|
+
- test/test_paramix_include.rb
|
47
51
|
- test/test_paramix_inject.rb
|
48
52
|
- test/test_paramix_namespace.rb
|
49
53
|
- LICENSE
|
50
54
|
- README.rdoc
|
51
55
|
- HISTORY
|
52
|
-
- Syckfile
|
53
56
|
has_rdoc: true
|
54
57
|
homepage: http://rubyworks.github.com/paramix
|
55
58
|
licenses: []
|
@@ -82,7 +85,11 @@ signing_key:
|
|
82
85
|
specification_version: 3
|
83
86
|
summary: Parametric Mixins
|
84
87
|
test_files:
|
85
|
-
- test/
|
88
|
+
- test/nested/test_nested_both.rb
|
89
|
+
- test/nested/test_nested_bottom.rb
|
90
|
+
- test/nested/test_nested_top.rb
|
86
91
|
- test/test_paramix_callback.rb
|
92
|
+
- test/test_paramix_extend.rb
|
93
|
+
- test/test_paramix_include.rb
|
87
94
|
- test/test_paramix_inject.rb
|
88
95
|
- test/test_paramix_namespace.rb
|
data/Syckfile
DELETED
@@ -1,79 +0,0 @@
|
|
1
|
-
---
|
2
|
-
announce:
|
3
|
-
service : Email
|
4
|
-
file : ~
|
5
|
-
subject : ~
|
6
|
-
mailto : ruby-talk@ruby-lang.org
|
7
|
-
active : true
|
8
|
-
|
9
|
-
box:
|
10
|
-
service: Box
|
11
|
-
active : true
|
12
|
-
types : [gem, tar]
|
13
|
-
include: [bin, demo, lib, meta, test, "[A-Z]*"]
|
14
|
-
exclude: ~
|
15
|
-
|
16
|
-
rdoc:
|
17
|
-
service : RDoc
|
18
|
-
template : redfish
|
19
|
-
include : ~
|
20
|
-
exclude : ~
|
21
|
-
main : ~
|
22
|
-
extra : ~
|
23
|
-
active : true
|
24
|
-
|
25
|
-
ridoc:
|
26
|
-
service: RIDoc
|
27
|
-
include: ~
|
28
|
-
exclude: ~
|
29
|
-
active : true
|
30
|
-
|
31
|
-
notes:
|
32
|
-
service : DNotes
|
33
|
-
loadpath : ~
|
34
|
-
labels : ~
|
35
|
-
output : ~
|
36
|
-
format : ~
|
37
|
-
active : false
|
38
|
-
|
39
|
-
stats:
|
40
|
-
service : Stats
|
41
|
-
title : ~
|
42
|
-
loadpath : ~
|
43
|
-
exclude : ~
|
44
|
-
output : ~
|
45
|
-
active : true
|
46
|
-
|
47
|
-
testrb:
|
48
|
-
service : testrb
|
49
|
-
tests : ~
|
50
|
-
exclude : ~
|
51
|
-
loadpath : ~
|
52
|
-
requires : ~
|
53
|
-
live : false
|
54
|
-
active : true
|
55
|
-
|
56
|
-
syntax:
|
57
|
-
service : Syntax
|
58
|
-
loadpath : ~
|
59
|
-
exclude : ~
|
60
|
-
active : false
|
61
|
-
|
62
|
-
vclog:
|
63
|
-
service : VClog
|
64
|
-
format : html # xml, txt
|
65
|
-
layout : rel # gnu
|
66
|
-
typed : false
|
67
|
-
output : ~
|
68
|
-
active : false
|
69
|
-
|
70
|
-
|
71
|
-
#rubyforge:
|
72
|
-
# service : Rubyforge
|
73
|
-
# unixname: <%= project %>
|
74
|
-
# groupid : ~
|
75
|
-
# package : <%= package %>
|
76
|
-
# sitemap:
|
77
|
-
# doc/rdoc: <%= package %>
|
78
|
-
# active : false
|
79
|
-
|
data/test/test_paramix_basic.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'paramix'
|
2
|
-
require 'test/unit'
|
3
|
-
|
4
|
-
class TC_Paramix_Basic < Test::Unit::TestCase
|
5
|
-
|
6
|
-
module M
|
7
|
-
include Paramix
|
8
|
-
|
9
|
-
def f
|
10
|
-
mixin_params[M][:p]
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
class C
|
15
|
-
extend M[:p => "mosh"]
|
16
|
-
end
|
17
|
-
|
18
|
-
class D
|
19
|
-
extend M[:p => "many"]
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_03_001
|
23
|
-
assert_equal( "mosh", C.f )
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_03_002
|
27
|
-
assert_equal( "many", D.f )
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_03_003
|
31
|
-
assert_equal( {M=>{:p => "mosh"}}, (class << C; self; end).mixin_parameters )
|
32
|
-
assert_equal( {M=>{:p => "many"}}, (class << D; self; end).mixin_parameters )
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
|