blockenspiel 0.3.1-java → 0.3.2-java

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/Blockenspiel.rdoc CHANGED
@@ -314,6 +314,8 @@ multiple threads trying to mix methods into the same object concurrently.
314
314
 
315
315
  * Implementing wildcard DSL methods using <tt>method_missing</tt> doesn't
316
316
  work. I haven't yet figured out the right semantics for this case.
317
+ * Including Blockenspiel::DSL in a module is not yet supported, but this
318
+ is planned in a future release.
317
319
 
318
320
  === Development and support
319
321
 
data/History.rdoc CHANGED
@@ -1,3 +1,11 @@
1
+ === 0.3.2 / 2009-11-17
2
+
3
+ * Modules included in a DSL-ized class now have their methods included in
4
+ the DSL.
5
+ * Raise a more informative error (for now) when trying to include
6
+ Blockenspiel::DSL in a module. At some point, we'll support this usage,
7
+ once I figure out the right semantics for it.
8
+
1
9
  === 0.3.1 / 2009-11-08
2
10
 
3
11
  * Blockenspiel#invoke can now take its options hash as the second argument
data/README.rdoc CHANGED
@@ -66,6 +66,8 @@ For an extended analysis of different ways to implement DSL blocks, see
66
66
 
67
67
  * Implementing wildcard DSL methods using <tt>method_missing</tt> doesn't
68
68
  work. I haven't yet figured out the right semantics for this case.
69
+ * Including Blockenspiel::DSL in a module is not yet supported, but this
70
+ is planned in a future release.
69
71
 
70
72
  === Development and support
71
73
 
@@ -95,6 +95,12 @@ module Blockenspiel
95
95
  ::Blockenspiel::DSLSetupMethods._setup_class(subklass_)
96
96
  super
97
97
  end
98
+ class << klass_
99
+ unless private_method_defined?(:_blockenspiel_default_include)
100
+ alias_method :_blockenspiel_default_include, :include
101
+ alias_method :include, :_blockenspiel_custom_include
102
+ end
103
+ end
98
104
  end
99
105
  end
100
106
 
@@ -121,10 +127,9 @@ module Blockenspiel
121
127
  end
122
128
 
123
129
 
124
- # Hook called when a method is added.
125
- # This automatically makes the method a DSL method according to the current setting.
130
+ # Automatically make the given method a DSL method according to the current setting.
126
131
 
127
- def method_added(symbol_) # :nodoc:
132
+ def _blockenspiel_auto_dsl_method(symbol_) # :nodoc:
128
133
  if @_blockenspiel_active
129
134
  dsl_method(symbol_)
130
135
  elsif @_blockenspiel_active.nil?
@@ -132,10 +137,34 @@ module Blockenspiel
132
137
  dsl_method(symbol_)
133
138
  end
134
139
  end
140
+ end
141
+
142
+
143
+ # Hook called when a method is added.
144
+ # This calls _blockenspiel_auto_dsl_method to auto-handle the method,
145
+ # possibly making it a DSL method according to the current setting.
146
+
147
+ def method_added(symbol_) # :nodoc:
148
+ _blockenspiel_auto_dsl_method(symbol_)
135
149
  super
136
150
  end
137
151
 
138
152
 
153
+ # Custom include method. Calls the main include implementation, but also
154
+ # goes through the public methods of the included module and calls
155
+ # _blockenspiel_auto_dsl_method on each to make them DSL methods
156
+ # (possibly) according to the current setting.
157
+
158
+ def _blockenspiel_custom_include(*modules_) # :nodoc:
159
+ _blockenspiel_default_include(*modules_)
160
+ modules_.reverse_each do |mod_|
161
+ mod_.public_instance_methods.each do |method_|
162
+ _blockenspiel_auto_dsl_method(method_)
163
+ end
164
+ end
165
+ end
166
+
167
+
139
168
  # Get this class's corresponding DSL module
140
169
 
141
170
  def _get_blockenspiel_module # :nodoc:
@@ -328,6 +357,9 @@ module Blockenspiel
328
357
  module DSL
329
358
 
330
359
  def self.included(klass_) # :nodoc:
360
+ unless klass_.kind_of?(::Class)
361
+ raise ::Blockenspiel::BlockenspielError, "You cannot include Blockenspiel::DSL in a module (yet)"
362
+ end
331
363
  klass_.extend(::Blockenspiel::DSLSetupMethods)
332
364
  end
333
365
 
@@ -37,7 +37,7 @@
37
37
  module Blockenspiel
38
38
 
39
39
  # Current gem version, as a frozen string.
40
- VERSION_STRING = '0.3.1'.freeze
40
+ VERSION_STRING = '0.3.2'.freeze
41
41
 
42
42
  autoload(:VERSION, ::File.dirname(__FILE__)+'/versionomy.rb')
43
43
 
Binary file
data/tests/tc_mixins.rb CHANGED
@@ -85,6 +85,38 @@ module Blockenspiel
85
85
  end
86
86
 
87
87
 
88
+ class Target3 < ::Blockenspiel::Base
89
+
90
+ def initialize(hash_)
91
+ @hash = hash_
92
+ end
93
+
94
+ def set_value(key_, value_)
95
+ @hash[key_] = value_
96
+ end
97
+
98
+ def _helper_method(key_)
99
+ @hash[key_]
100
+ end
101
+
102
+ def get_value(key_)
103
+ @hash[key_]
104
+ end
105
+ dsl_method :get_value, false
106
+
107
+ def get_value2(key_)
108
+ @hash[key_]
109
+ end
110
+ dsl_method :get_value2, false
111
+
112
+ end
113
+
114
+
115
+ def get_value(key_)
116
+ :helper
117
+ end
118
+
119
+
88
120
  # Basic test of mixin mechanism.
89
121
  #
90
122
  # * Asserts that the mixin methods are added and removed for a single mixin.
@@ -234,6 +266,28 @@ module Blockenspiel
234
266
  end
235
267
 
236
268
 
269
+ # Test mixin omissions.
270
+ #
271
+ # * Asserts that underscore methods are not mixed in.
272
+ # * Asserts that methods that are turned off after the fact cannot be called.
273
+
274
+ def test_omissions
275
+ hash_ = ::Hash.new
276
+ block_ = ::Proc.new do
277
+ set_value(:a, 1)
278
+ assert(!self.respond_to?(:_helper_method))
279
+ assert_equal(:helper, get_value(:a))
280
+ assert_raise(::NoMethodError) do
281
+ get_value2(:a)
282
+ end
283
+ end
284
+ target_ = Target3.new(hash_)
285
+ ::Blockenspiel.invoke(block_, target_)
286
+ assert(!self.respond_to?(:set_value))
287
+ assert_equal(1, target_.get_value(:a))
288
+ end
289
+
290
+
237
291
  end
238
292
 
239
293
  end
@@ -0,0 +1,188 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Blockenspiel module tests
4
+ #
5
+ # This file contains tests for DSL module inclusion.
6
+ #
7
+ # -----------------------------------------------------------------------------
8
+ # Copyright 2008-2009 Daniel Azuma
9
+ #
10
+ # All rights reserved.
11
+ #
12
+ # Redistribution and use in source and binary forms, with or without
13
+ # modification, are permitted provided that the following conditions are met:
14
+ #
15
+ # * Redistributions of source code must retain the above copyright notice,
16
+ # this list of conditions and the following disclaimer.
17
+ # * Redistributions in binary form must reproduce the above copyright notice,
18
+ # this list of conditions and the following disclaimer in the documentation
19
+ # and/or other materials provided with the distribution.
20
+ # * Neither the name of the copyright holder, nor the names of any other
21
+ # contributors to this software, may be used to endorse or promote products
22
+ # derived from this software without specific prior written permission.
23
+ #
24
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34
+ # POSSIBILITY OF SUCH DAMAGE.
35
+ # -----------------------------------------------------------------------------
36
+ ;
37
+
38
+
39
+ require 'test/unit'
40
+ require ::File.expand_path("#{::File.dirname(__FILE__)}/../lib/blockenspiel.rb")
41
+
42
+
43
+ module Blockenspiel
44
+ module Tests # :nodoc:
45
+
46
+ class TestBasic < ::Test::Unit::TestCase # :nodoc:
47
+
48
+
49
+ class Target1
50
+ include ::Blockenspiel::DSL
51
+
52
+ def initialize
53
+ @hash = ::Hash.new
54
+ end
55
+
56
+ def set_value(key_, value_)
57
+ @hash[key_] = value_
58
+ end
59
+
60
+ def _helper_method(key_, value_)
61
+ @hash[key_] = value_
62
+ end
63
+
64
+ def get_value(key_)
65
+ @hash[key_]
66
+ end
67
+ dsl_method :get_value, false
68
+
69
+ def get_value2(key_)
70
+ @hash[key_]
71
+ end
72
+ dsl_method :get_value2, false
73
+
74
+ end
75
+
76
+
77
+ module Module2
78
+
79
+ def set_value(key_, value_)
80
+ @hash[key_] = value_
81
+ end
82
+
83
+ def _get_value(key_)
84
+ @hash[key_]
85
+ end
86
+
87
+ end
88
+
89
+ class Target2a
90
+ include ::Blockenspiel::DSL
91
+
92
+ def initialize
93
+ @hash = ::Hash.new
94
+ end
95
+
96
+ include Module2
97
+ end
98
+
99
+ class Target2b
100
+ include ::Blockenspiel::DSL
101
+
102
+ def initialize
103
+ @hash = ::Hash.new
104
+ end
105
+ end
106
+
107
+ class Target2c < Target2b
108
+ include Module2
109
+ end
110
+
111
+
112
+ # Helper method
113
+
114
+ def get_value(key_)
115
+ return :helper
116
+ end
117
+
118
+
119
+ # Test simple usage.
120
+ #
121
+ # * Asserts that methods are mixed in to self.
122
+ # * Asserts that methods are removed from self afterward.
123
+ # * Asserts that the specified target object still receives the messages.
124
+
125
+ def test_simple_target
126
+ block_ = ::Proc.new do
127
+ set_value(:a, 1)
128
+ end
129
+ target_ = Target1.new
130
+ ::Blockenspiel.invoke(block_, target_)
131
+ assert(!self.respond_to?(:set_value))
132
+ assert_equal(1, target_.get_value(:a))
133
+ end
134
+
135
+
136
+ # Test omissions.
137
+ #
138
+ # * Asserts that underscore methods are not mixed in.
139
+ # * Asserts that methods that are turned off after the fact cannot be called.
140
+
141
+ def test_omissions
142
+ block_ = ::Proc.new do
143
+ set_value(:a, 1)
144
+ assert(!self.respond_to?(:_helper_method))
145
+ assert_equal(:helper, get_value(:a))
146
+ assert_raise(::NoMethodError) do
147
+ get_value2(:a)
148
+ end
149
+ end
150
+ target_ = Target1.new
151
+ ::Blockenspiel.invoke(block_, target_)
152
+ end
153
+
154
+
155
+ # Test module inclusion.
156
+ #
157
+ # * Asserts that methods from an included module are handled.
158
+
159
+ def test_simple_module_inclusion
160
+ block_ = ::Proc.new do
161
+ set_value(:a, 1)
162
+ assert(!self.respond_to?(:_get_value))
163
+ end
164
+ target_ = Target2a.new
165
+ ::Blockenspiel.invoke(block_, target_)
166
+ assert_equal(1, target_._get_value(:a))
167
+ end
168
+
169
+
170
+ # Test module inclusion from a subclass
171
+ #
172
+ # * Asserts that a module can be included from a DSL subclass.
173
+
174
+ def test_simple_module_inclusion_from_subclass
175
+ block_ = ::Proc.new do
176
+ set_value(:a, 1)
177
+ assert(!self.respond_to?(:_get_value))
178
+ end
179
+ target_ = Target2c.new
180
+ ::Blockenspiel.invoke(block_, target_)
181
+ assert_equal(1, target_._get_value(:a))
182
+ end
183
+
184
+
185
+ end
186
+
187
+ end
188
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blockenspiel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: java
6
6
  authors:
7
7
  - Daniel Azuma
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-08 00:00:00 -08:00
12
+ date: 2009-11-17 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -32,18 +32,19 @@ files:
32
32
  - lib/blockenspiel/impl.rb
33
33
  - lib/blockenspiel/version.rb
34
34
  - lib/blockenspiel/versionomy.rb
35
+ - lib/blockenspiel_unmixer.jar
35
36
  - tests/tc_basic.rb
36
37
  - tests/tc_behaviors.rb
37
38
  - tests/tc_dsl_attrs.rb
38
39
  - tests/tc_dsl_methods.rb
39
40
  - tests/tc_dynamic.rb
40
41
  - tests/tc_mixins.rb
42
+ - tests/tc_modules.rb
41
43
  - Blockenspiel.rdoc
42
44
  - History.rdoc
43
45
  - ImplementingDSLblocks.rdoc
44
46
  - README.rdoc
45
47
  - Rakefile
46
- - lib/blockenspiel_unmixer.jar
47
48
  has_rdoc: true
48
49
  homepage: http://virtuoso.rubyforge.org/blockenspiel
49
50
  licenses: []
@@ -79,3 +80,4 @@ test_files:
79
80
  - tests/tc_dsl_methods.rb
80
81
  - tests/tc_dynamic.rb
81
82
  - tests/tc_mixins.rb
83
+ - tests/tc_modules.rb