blockenspiel 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,12 @@
1
+ === 0.4.2 / 2011-06-02
2
+
3
+ * Fixed an unmixer compatibility issue with Rubinius > 1.2.x. (Thanks to @meh for the fix.)
4
+ * Recent versions of Rubinius raised exceptions involving Fiber. Fixed.
5
+ * Workaround for a JRuby NullPointerException (JRUBY-5842).
6
+ * Integrated JRuby platform gem back into main gem.
7
+ * A .gemspec file is now available for gem building and bundler git integration.
8
+ * Some cleanup of the Rakefile and tests.
9
+
1
10
  === 0.4.1 / 2010-06-23
2
11
 
3
12
  * Support for rubinius 1.0.
data/Version ADDED
@@ -0,0 +1 @@
1
+ 0.4.2
@@ -34,5 +34,13 @@
34
34
  ;
35
35
 
36
36
 
37
- require 'mkmf'
38
- create_makefile 'blockenspiel/unmixer_mri'
37
+ if ::RUBY_DESCRIPTION =~ /^jruby\s/
38
+
39
+ ::File.open('Makefile', 'w'){ |f_| f_.write(".PHONY: install\ninstall:\n") }
40
+
41
+ else
42
+
43
+ require 'mkmf'
44
+ create_makefile 'blockenspiel/unmixer_mri'
45
+
46
+ end
@@ -47,7 +47,7 @@
47
47
  */
48
48
 
49
49
 
50
- #include "ruby.h"
50
+ #include <ruby.h>
51
51
 
52
52
 
53
53
  #ifndef RCLASS_SUPER
@@ -43,24 +43,19 @@ module Blockenspiel
43
43
  end
44
44
 
45
45
 
46
- includes_ = [
47
- 'errors',
48
- 'dsl_setup',
49
- 'builder',
50
- 'impl',
51
- 'version',
52
- ]
53
-
54
-
55
- dir_ = ::File.expand_path('blockenspiel', ::File.dirname(__FILE__))
56
46
  case ::RUBY_DESCRIPTION
57
47
  when /^ruby\s/
58
- includes_.unshift('unmixer_mri')
48
+ require 'blockenspiel/unmixer_mri'
59
49
  when /^jruby\s/
60
- require "blockenspiel_unmixer_jruby"
50
+ require 'blockenspiel_unmixer_jruby'
61
51
  when /^rubinius\s/
62
- includes_.unshift('unmixer_rubinius')
52
+ require 'blockenspiel/unmixer_rubinius'
63
53
  else
64
- includes_.unshift('unmixer_unimplemented')
54
+ require 'blockenspiel/unmixer_unimplemented'
65
55
  end
66
- includes_.each{ |file_| require "#{dir_}/#{file_}" }
56
+
57
+ require 'blockenspiel/errors'
58
+ require 'blockenspiel/dsl_setup'
59
+ require 'blockenspiel/builder'
60
+ require 'blockenspiel/impl'
61
+ require 'blockenspiel/version'
@@ -121,34 +121,34 @@ module Blockenspiel
121
121
  # Following are the options understood by Blockenspiel when providing
122
122
  # code using a block:
123
123
  #
124
- # <tt>:parameterless</tt>::
124
+ # [<tt>:parameterless</tt>]
125
125
  # If set to false, disables parameterless blocks and always attempts to
126
126
  # pass a parameter to the block. Otherwise, you may set it to one of
127
127
  # three behaviors for parameterless blocks: <tt>:mixin</tt> (the
128
128
  # default), <tt>:instance</tt>, and <tt>:proxy</tt>. See below for
129
129
  # detailed descriptions of these behaviors. This option key is also
130
130
  # available as <tt>:behavior</tt>.
131
- # <tt>:parameter</tt>::
131
+ # [<tt>:parameter</tt>]
132
132
  # If set to false, disables blocks with parameters, and always attempts
133
133
  # to use parameterless blocks. Default is true, enabling parameter mode.
134
134
  #
135
135
  # The following values control the precise behavior of parameterless
136
136
  # blocks. These are values for the <tt>:parameterless</tt> option.
137
137
  #
138
- # <tt>:mixin</tt>::
138
+ # [<tt>:mixin</tt>]
139
139
  # This is the default behavior. DSL methods from the target are
140
140
  # temporarily overlayed on the caller's +self+ object, but +self+ still
141
141
  # points to the same object, so the helper methods and instance
142
142
  # variables from the caller's closure remain available. The DSL methods
143
143
  # are removed when the block completes.
144
- # <tt>:instance</tt>::
144
+ # [<tt>:instance</tt>]
145
145
  # This behavior actually changes +self+ to the target object using
146
146
  # <tt>instance_eval</tt>. Thus, the caller loses access to its own
147
147
  # helper methods and instance variables, and instead gains access to the
148
148
  # target object's instance variables. The target object's methods are
149
149
  # not modified: this behavior does not apply any DSL method changes
150
150
  # specified using <tt>dsl_method</tt> directives.
151
- # <tt>:proxy</tt>::
151
+ # [<tt>:proxy</tt>]
152
152
  # This behavior changes +self+ to a proxy object created by applying the
153
153
  # DSL methods to an empty object, whose <tt>method_missing</tt> points
154
154
  # back at the block's context. This behavior is a compromise between
@@ -169,19 +169,19 @@ module Blockenspiel
169
169
  # <tt>:parameter</tt>, are meaningless and ignored. However, the
170
170
  # following new options are recognized:
171
171
  #
172
- # <tt>:file</tt>::
172
+ # [<tt>:file</tt>]
173
173
  # The value of this option should be a string indicating the path to
174
174
  # the file from which the user's DSL code is coming. It is passed
175
175
  # as the "file" parameter to eval; that is, it is included in the stack
176
176
  # trace should an exception be thrown out of the DSL. If no code string
177
177
  # is provided directly, this option is required and must be set to the
178
178
  # path of the file from which to load the code.
179
- # <tt>:line</tt>::
179
+ # [<tt>:line</tt>]
180
180
  # This option is passed as the "line" parameter to eval; that is, it
181
181
  # indicates the starting line number for the code string, and is used
182
182
  # to compute line numbers for the stack trace should an exception be
183
183
  # thrown out of the DSL. This option is optional and defaults to 1.
184
- # <tt>:behavior</tt>::
184
+ # [<tt>:behavior</tt>]
185
185
  # Controls how the DSL is called. Recognized values are <tt>:proxy</tt>
186
186
  # (the default) and <tt>:instance</tt>. See below for detailed
187
187
  # descriptions of these behaviors. Note that <tt>:mixin</tt> is not
@@ -190,14 +190,14 @@ module Blockenspiel
190
190
  #
191
191
  # The following values are recognized for the <tt>:behavior</tt> option:
192
192
  #
193
- # <tt>:proxy</tt>::
193
+ # [<tt>:proxy</tt>]
194
194
  # This behavior changes +self+ to a proxy object created by applying the
195
195
  # DSL methods to an empty object. Thus, the code in the DSL string does
196
196
  # not have access to the target object's internal instance variables or
197
197
  # private methods. Furthermore, the transformations specified by
198
198
  # <tt>dsl_method</tt> directives are honored. This is the default
199
199
  # behavior.
200
- # <tt>:instance</tt>::
200
+ # [<tt>:instance</tt>]
201
201
  # This behavior actually changes +self+ to the target object using
202
202
  # <tt>instance_eval</tt>. Thus, the code in the DSL string gains access
203
203
  # to the target object's instance variables and private methods. Also,
@@ -528,8 +528,14 @@ module Blockenspiel
528
528
 
529
529
  begin
530
530
  require 'fiber'
531
+ raise ::LoadError unless defined?(::Fiber)
531
532
  def self._current_context_id # :nodoc:
532
- ::Fiber.current.object_id
533
+ begin
534
+ ::Fiber.current.object_id
535
+ rescue ::Exception
536
+ # JRuby hack (see JRUBY-5842)
537
+ ::Thread.current.object_id
538
+ end
533
539
  end
534
540
  rescue ::LoadError
535
541
  def self._current_context_id # :nodoc:
@@ -41,6 +41,8 @@ module Blockenspiel
41
41
 
42
42
  module Unmixer
43
43
 
44
+ @old_metaclass = ''.respond_to?(:metaclass)
45
+
44
46
 
45
47
  # Unmix a module from an object in Rubinius.
46
48
  #
@@ -52,7 +54,7 @@ module Blockenspiel
52
54
  # Rubinius 1.0 release.
53
55
 
54
56
  def self.unmix(obj_, mod_) # :nodoc:
55
- last_super_ = obj_.metaclass
57
+ last_super_ = @old_metaclass ? obj_.metaclass : obj_.singleton_class
56
58
  this_super_ = last_super_.direct_superclass
57
59
  while this_super_
58
60
  if (this_super_ == mod_ || this_super_.respond_to?(:module) && this_super_.module == mod_)
@@ -37,7 +37,7 @@
37
37
  module Blockenspiel
38
38
 
39
39
  # Current gem version, as a frozen string.
40
- VERSION_STRING = '0.4.1'.freeze
40
+ VERSION_STRING = ::File.read(::File.dirname(__FILE__)+'/../../Version').strip.freeze
41
41
 
42
42
  autoload(:VERSION, ::File.dirname(__FILE__)+'/versionomy.rb')
43
43
 
File without changes
@@ -37,7 +37,7 @@
37
37
 
38
38
 
39
39
  require 'test/unit'
40
- require ::File.expand_path("#{::File.dirname(__FILE__)}/../lib/blockenspiel.rb")
40
+ require 'blockenspiel'
41
41
 
42
42
 
43
43
  module Blockenspiel
@@ -37,13 +37,13 @@
37
37
 
38
38
 
39
39
  require 'test/unit'
40
- require ::File.expand_path("#{::File.dirname(__FILE__)}/../lib/blockenspiel.rb")
40
+ require 'blockenspiel'
41
41
 
42
42
 
43
43
  module Blockenspiel
44
44
  module Tests # :nodoc:
45
45
 
46
- class TextBehaviors < ::Test::Unit::TestCase # :nodoc:
46
+ class TestBehaviors < ::Test::Unit::TestCase # :nodoc:
47
47
 
48
48
 
49
49
  class Target1 < ::Blockenspiel::Base
@@ -96,7 +96,7 @@ module Blockenspiel
96
96
  context_self_.assert_raise(::NoMethodError){ set_value3_dslversion('d', 4) }
97
97
  context_self_.assert_raise(::NoMethodError){ helper_method() }
98
98
  context_self_.assert(!instance_variable_defined?(:@my_instance_variable_test))
99
- context_self_.assert_instance_of(::Blockenspiel::Tests::TextBehaviors::Target1, self)
99
+ context_self_.assert_instance_of(::Blockenspiel::Tests::TestBehaviors::Target1, self)
100
100
  end
101
101
  ::Blockenspiel.invoke(block_, Target1.new(hash_), :parameterless => :instance)
102
102
  assert_equal(1, hash_['a1'])
@@ -123,7 +123,7 @@ module Blockenspiel
123
123
  context_self_.assert_raise(::NoMethodError){ set_value3('d', 4) }
124
124
  context_self_.assert(helper_method())
125
125
  context_self_.assert(!instance_variable_defined?(:@my_instance_variable_test))
126
- context_self_.assert(!self.kind_of?(::Blockenspiel::Tests::TextBehaviors::Target1))
126
+ context_self_.assert(!self.kind_of?(::Blockenspiel::Tests::TestBehaviors::Target1))
127
127
  context_self_.assert_not_equal(context_self_, self)
128
128
  end
129
129
  ::Blockenspiel.invoke(block_, Target1.new(hash_), :parameterless => :proxy)
@@ -37,7 +37,7 @@
37
37
 
38
38
 
39
39
  require 'test/unit'
40
- require ::File.expand_path("#{::File.dirname(__FILE__)}/../lib/blockenspiel.rb")
40
+ require 'blockenspiel'
41
41
 
42
42
 
43
43
  module Blockenspiel
@@ -37,7 +37,7 @@
37
37
 
38
38
 
39
39
  require 'test/unit'
40
- require ::File.expand_path("#{::File.dirname(__FILE__)}/../lib/blockenspiel.rb")
40
+ require 'blockenspiel'
41
41
 
42
42
 
43
43
  module Blockenspiel
@@ -37,7 +37,7 @@
37
37
 
38
38
 
39
39
  require 'test/unit'
40
- require ::File.expand_path("#{::File.dirname(__FILE__)}/../lib/blockenspiel.rb")
40
+ require 'blockenspiel'
41
41
 
42
42
 
43
43
  module Blockenspiel
@@ -0,0 +1,93 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Blockenspiel behavior tests
4
+ #
5
+ # This file contains tests for behavior settings.
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 'blockenspiel'
41
+
42
+
43
+ module Blockenspiel
44
+ module Tests # :nodoc:
45
+
46
+ class TestEmbeddedBlock < ::Test::Unit::TestCase # :nodoc:
47
+
48
+
49
+ class Target1 < ::Blockenspiel::Base
50
+
51
+ def initialize(value_)
52
+ @value = value_
53
+ @block = nil
54
+ end
55
+
56
+ def set_block(&block_)
57
+ @block = block_
58
+ end
59
+
60
+ def value
61
+ @value
62
+ end
63
+
64
+ dsl_methods false
65
+
66
+ def call_block
67
+ @block.call
68
+ end
69
+
70
+ end
71
+
72
+
73
+ BLOCK = ::Proc.new do
74
+ set_block do
75
+ self.value
76
+ end
77
+ end
78
+
79
+
80
+ # Test an embedded block with a proxy.
81
+
82
+ def test_proxy_embedded_block
83
+ return # TEMP
84
+ target_ = Target1.new(23)
85
+ ::Blockenspiel.invoke(BLOCK, target_, :parameterless => :proxy)
86
+ assert_equal(23, target_.call_block)
87
+ end
88
+
89
+
90
+ end
91
+
92
+ end
93
+ end
@@ -38,7 +38,7 @@
38
38
 
39
39
 
40
40
  require 'test/unit'
41
- require ::File.expand_path("#{::File.dirname(__FILE__)}/../lib/blockenspiel.rb")
41
+ require 'blockenspiel'
42
42
 
43
43
 
44
44
  module Blockenspiel
@@ -37,7 +37,7 @@
37
37
 
38
38
 
39
39
  require 'test/unit'
40
- require ::File.expand_path("#{::File.dirname(__FILE__)}/../lib/blockenspiel.rb")
40
+ require 'blockenspiel'
41
41
 
42
42
 
43
43
  module Blockenspiel
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blockenspiel
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 4
9
- - 1
10
- version: 0.4.1
4
+ prerelease:
5
+ version: 0.4.2
11
6
  platform: ruby
12
7
  authors:
13
8
  - Daniel Azuma
@@ -15,8 +10,7 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2010-06-23 00:00:00 -07:00
19
- default_executable:
13
+ date: 2011-06-03 00:00:00 Z
20
14
  dependencies: []
21
15
 
22
16
  description: Blockenspiel is a helper library designed to make it easy to implement DSL blocks. It is designed to be comprehensive and robust, supporting most common usage patterns, and working correctly in the presence of nested blocks and multithreading.
@@ -24,16 +18,13 @@ email: dazuma@gmail.com
24
18
  executables: []
25
19
 
26
20
  extensions:
27
- - ext/blockenspiel/extconf.rb
21
+ - ext/unmixer/extconf.rb
28
22
  extra_rdoc_files:
29
- - README.rdoc
30
23
  - Blockenspiel.rdoc
31
24
  - History.rdoc
32
25
  - ImplementingDSLblocks.rdoc
26
+ - README.rdoc
33
27
  files:
34
- - ext/blockenspiel/unmixer_mri.c
35
- - ext/blockenspiel/extconf.rb
36
- - ext/blockenspiel/BlockenspielUnmixerJrubyService.java
37
28
  - lib/blockenspiel/builder.rb
38
29
  - lib/blockenspiel/dsl_setup.rb
39
30
  - lib/blockenspiel/errors.rb
@@ -43,21 +34,22 @@ files:
43
34
  - lib/blockenspiel/version.rb
44
35
  - lib/blockenspiel/versionomy.rb
45
36
  - lib/blockenspiel.rb
46
- - lib/blockenspiel_unmixer_jruby.jar
47
- - tests/files/file1.rb
48
- - tests/tc_basic.rb
49
- - tests/tc_behaviors.rb
50
- - tests/tc_dsl_attrs.rb
51
- - tests/tc_dsl_methods.rb
52
- - tests/tc_dynamic.rb
53
- - tests/tc_mixins.rb
54
- - tests/tc_modules.rb
37
+ - ext/unmixer/unmixer_mri.c
38
+ - ext/unmixer/extconf.rb
39
+ - test/files/file1.rb
40
+ - test/tc_basic.rb
41
+ - test/tc_behaviors.rb
42
+ - test/tc_dsl_attrs.rb
43
+ - test/tc_dsl_methods.rb
44
+ - test/tc_dynamic.rb
45
+ - test/tc_embedded_block.rb
46
+ - test/tc_mixins.rb
47
+ - test/tc_modules.rb
55
48
  - Blockenspiel.rdoc
56
49
  - History.rdoc
57
50
  - ImplementingDSLblocks.rdoc
58
51
  - README.rdoc
59
- - Rakefile
60
- has_rdoc: true
52
+ - Version
61
53
  homepage: http://virtuoso.rubyforge.org/blockenspiel
62
54
  licenses: []
63
55
 
@@ -71,33 +63,26 @@ required_ruby_version: !ruby/object:Gem::Requirement
71
63
  requirements:
72
64
  - - ">="
73
65
  - !ruby/object:Gem::Version
74
- hash: 57
75
- segments:
76
- - 1
77
- - 8
78
- - 7
79
66
  version: 1.8.7
80
67
  required_rubygems_version: !ruby/object:Gem::Requirement
81
68
  none: false
82
69
  requirements:
83
- - - ">="
70
+ - - ">"
84
71
  - !ruby/object:Gem::Version
85
- hash: 3
86
- segments:
87
- - 0
88
- version: "0"
72
+ version: 1.3.1
89
73
  requirements: []
90
74
 
91
75
  rubyforge_project: virtuoso
92
- rubygems_version: 1.3.7
76
+ rubygems_version: 1.8.5
93
77
  signing_key:
94
78
  specification_version: 3
95
79
  summary: Blockenspiel is a helper library designed to make it easy to implement DSL blocks.
96
80
  test_files:
97
- - tests/tc_basic.rb
98
- - tests/tc_behaviors.rb
99
- - tests/tc_dsl_attrs.rb
100
- - tests/tc_dsl_methods.rb
101
- - tests/tc_dynamic.rb
102
- - tests/tc_mixins.rb
103
- - tests/tc_modules.rb
81
+ - test/tc_basic.rb
82
+ - test/tc_behaviors.rb
83
+ - test/tc_dsl_attrs.rb
84
+ - test/tc_dsl_methods.rb
85
+ - test/tc_dynamic.rb
86
+ - test/tc_embedded_block.rb
87
+ - test/tc_mixins.rb
88
+ - test/tc_modules.rb
data/Rakefile DELETED
@@ -1,274 +0,0 @@
1
- # -----------------------------------------------------------------------------
2
- #
3
- # Blockenspiel Rakefile
4
- #
5
- # -----------------------------------------------------------------------------
6
- # Copyright 2008-2010 Daniel Azuma
7
- #
8
- # All rights reserved.
9
- #
10
- # Redistribution and use in source and binary forms, with or without
11
- # modification, are permitted provided that the following conditions are met:
12
- #
13
- # * Redistributions of source code must retain the above copyright notice,
14
- # this list of conditions and the following disclaimer.
15
- # * Redistributions in binary form must reproduce the above copyright notice,
16
- # this list of conditions and the following disclaimer in the documentation
17
- # and/or other materials provided with the distribution.
18
- # * Neither the name of the copyright holder, nor the names of any other
19
- # contributors to this software, may be used to endorse or promote products
20
- # derived from this software without specific prior written permission.
21
- #
22
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
- # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
- # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
- # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26
- # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
- # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
- # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
- # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
- # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
- # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
- # POSSIBILITY OF SUCH DAMAGE.
33
- # -----------------------------------------------------------------------------
34
- ;
35
-
36
-
37
- require 'rubygems'
38
- require 'rake'
39
- require 'rake/clean'
40
- require 'rake/testtask'
41
- require 'rake/rdoctask'
42
- require 'rdoc'
43
- require 'rdoc/rdoc'
44
- require 'rdoc/generator/darkfish'
45
-
46
- require ::File.expand_path("#{::File.dirname(__FILE__)}/lib/blockenspiel/version")
47
-
48
-
49
- # Configuration
50
-
51
- EXTRA_RDOC_FILES = ['README.rdoc', 'Blockenspiel.rdoc', 'History.rdoc', 'ImplementingDSLblocks.rdoc']
52
-
53
-
54
- # Environment configuration
55
-
56
- dlext_ = Config::CONFIG['DLEXT']
57
- platform_ =
58
- case ::RUBY_DESCRIPTION
59
- when /^jruby\s/ then :jruby
60
- when /^ruby\s/ then :mri
61
- when /^rubinius\s/ then :rubinius
62
- else :unknown
63
- end
64
-
65
-
66
- # Default task
67
-
68
- task :default => [:clean, :rdoc, :package, :test]
69
-
70
-
71
- # Clean task
72
-
73
- CLEAN.include(['ext/blockenspiel/Makefile*', "**/*.#{dlext_}", "**/*.rbc", 'ext/blockenspiel/*.o', '**/*.jar', 'ext/blockenspiel/*.class', 'idslb_markdown.txt', 'doc', 'pkg'])
74
-
75
-
76
- # Test task
77
-
78
- task :test => :build
79
- ::Rake::TestTask.new('test') do |task_|
80
- task_.pattern = 'tests/tc_*.rb'
81
- end
82
-
83
-
84
- # RDoc task
85
-
86
- ::Rake::RDocTask.new do |task_|
87
- task_.main = 'README.rdoc'
88
- task_.rdoc_files.include(*EXTRA_RDOC_FILES)
89
- task_.rdoc_files.include(['lib/blockenspiel.rb', 'lib/blockenspiel/*.rb'])
90
- task_.rdoc_dir = 'doc'
91
- task_.title = "Blockenspiel #{::Blockenspiel::VERSION_STRING} documentation"
92
- task_.options << '--format=darkfish'
93
- end
94
-
95
-
96
- # Gem package task
97
-
98
- task :package => [:build_jruby] do
99
- mkdir_p('pkg')
100
-
101
- # Common gemspec
102
- def create_gemspec
103
- ::Gem::Specification.new do |s_|
104
- s_.name = 'blockenspiel'
105
- s_.summary = 'Blockenspiel is a helper library designed to make it easy to implement DSL blocks.'
106
- s_.version = ::Blockenspiel::VERSION_STRING.dup
107
- s_.author = 'Daniel Azuma'
108
- s_.email = 'dazuma@gmail.com'
109
- s_.description = 'Blockenspiel is a helper library designed to make it easy to implement DSL blocks. It is designed to be comprehensive and robust, supporting most common usage patterns, and working correctly in the presence of nested blocks and multithreading.'
110
- s_.homepage = 'http://virtuoso.rubyforge.org/blockenspiel'
111
- s_.rubyforge_project = 'virtuoso'
112
- s_.required_ruby_version = '>= 1.8.7'
113
- s_.files = ::FileList['ext/**/*.{c,rb,java}', 'lib/**/*.{rb,jar}', 'tests/**/*.rb', '*.rdoc', 'Rakefile'].to_a
114
- s_.extra_rdoc_files = EXTRA_RDOC_FILES.dup
115
- s_.has_rdoc = true
116
- s_.test_files = FileList['tests/tc_*.rb']
117
- yield s_
118
- end
119
- end
120
-
121
- # Normal platform gemspec
122
- gemspec_ = create_gemspec do |s_|
123
- s_.platform = ::Gem::Platform::RUBY
124
- s_.extensions = ['ext/blockenspiel/extconf.rb']
125
- end
126
- ::Gem::Builder.new(gemspec_).build
127
- mv "blockenspiel-#{::Blockenspiel::VERSION_STRING}.gem", 'pkg'
128
-
129
- # JRuby gemspec
130
- gemspec_ = create_gemspec do |s_|
131
- s_.platform = 'java'
132
- s_.files += ['lib/blockenspiel_unmixer_jruby.jar']
133
- end
134
- ::Gem::Builder.new(gemspec_).build
135
- mv "blockenspiel-#{::Blockenspiel::VERSION_STRING}-java.gem", 'pkg'
136
- end
137
-
138
-
139
- # General build task
140
-
141
- case platform_
142
- when :jruby
143
- task :build => [:build_jruby]
144
- when :mri
145
- task :build => [:build_mri]
146
- else
147
- task :build
148
- end
149
-
150
-
151
- # Build tasks for MRI.
152
- # These are available only if the current rake is running under MRI.
153
- # They build the C extension for the current MRI.
154
-
155
- if platform_ == :mri
156
-
157
- if ::RUBY_VERSION =~ /^1\.8\..*$/
158
- mri_version_suffix_ = '18'
159
- elsif ::RUBY_VERSION =~ /^1\.9\..*$/
160
- mri_version_suffix_ = '19'
161
- else
162
- raise "Unknown version of Matz Ruby Interpreter (#{::RUBY_VERSION})"
163
- end
164
-
165
- makefile_name_ = "Makefile#{mri_version_suffix_}"
166
- unmixer_general_name_ = "unmixer_mri.#{dlext_}"
167
- unmixer_name_ = "unmixer_mri#{mri_version_suffix_}.#{dlext_}"
168
-
169
- desc 'Ensures the MRI C extension appropriate to the current platform is present'
170
- task :build_mri => ["ext/blockenspiel/#{unmixer_name_}"] do
171
- cp "ext/blockenspiel/#{unmixer_name_}", "lib/blockenspiel/#{unmixer_general_name_}"
172
- end
173
-
174
- file "ext/blockenspiel/#{unmixer_name_}" => ["ext/blockenspiel/#{makefile_name_}"] do
175
- ::Dir.chdir('ext/blockenspiel') do
176
- cp makefile_name_, 'Makefile'
177
- sh 'make'
178
- rm 'unmixer_mri.o'
179
- mv unmixer_general_name_, unmixer_name_
180
- end
181
- end
182
-
183
- file "ext/blockenspiel/#{makefile_name_}" do
184
- ::Dir.chdir('ext/blockenspiel') do
185
- ruby 'extconf.rb'
186
- mv 'Makefile', makefile_name_
187
- end
188
- end
189
-
190
- end
191
-
192
-
193
- # Build tasks for JRuby.
194
- # These are available under any ruby.
195
- # They assume that $JRUBY_HOME is set, and that the javac and jar
196
- # binaries are in the current path.
197
-
198
- desc 'Builds the JRuby extension'
199
- task :build_jruby => ['lib/blockenspiel_unmixer_jruby.jar']
200
-
201
- file 'lib/blockenspiel_unmixer_jruby.jar' do
202
- ::Dir.chdir('ext/blockenspiel') do
203
- sh 'javac -source 1.5 -target 1.5 -classpath $JRUBY_HOME/lib/jruby.jar BlockenspielUnmixerJrubyService.java'
204
- sh 'jar cf blockenspiel_unmixer_jruby.jar BlockenspielUnmixerJrubyService.class'
205
- end
206
- mv 'ext/blockenspiel/blockenspiel_unmixer_jruby.jar', 'lib'
207
- end
208
-
209
-
210
- # Publish RDocs
211
-
212
- desc 'Publishes RDocs to RubyForge'
213
- task :publish_rdoc_to_rubyforge => [:rerdoc] do
214
- config_ = ::YAML.load(::File.read(::File.expand_path("~/.rubyforge/user-config.yml")))
215
- username_ = config_['username']
216
- sh "rsync -av --delete doc/ #{username_}@rubyforge.org:/var/www/gforge-projects/virtuoso/blockenspiel"
217
- end
218
-
219
-
220
- # Publish gem
221
-
222
- task :release_gem => [:package] do |t_|
223
- v_ = ::ENV["VERSION"]
224
- abort "Must supply VERSION=x.y.z" unless v_
225
- if v_ != ::Blockenspiel::VERSION_STRING
226
- abort "Versions don't match: #{v_} vs #{::Blockenspiel::VERSION_STRING}"
227
- end
228
- puts "Releasing blockenspiel #{v_}"
229
- ::Dir.chdir('pkg') do
230
- sh "gem push blockenspiel-#{v_}.gem"
231
- sh "gem push blockenspiel-#{v_}-java.gem"
232
- end
233
- end
234
-
235
-
236
- # Publish everything
237
-
238
- task :release => [:release_gem, :publish_rdoc_to_rubyforge]
239
-
240
-
241
- # Custom task that takes the implementing dsl blocks paper
242
- # and converts it from RDoc format to Markdown
243
-
244
- task :idslb_markdown do
245
- ::File.open('ImplementingDSLblocks.rdoc') do |read_|
246
- ::File.open('idslb_markdown.txt', 'w') do |write_|
247
- linenum_ = 0
248
- read_.each do |line_|
249
- linenum_ += 1
250
- next if linenum_ < 4
251
- line_.sub!(/^===\ /, '### ')
252
- line_.sub!(/^\ \ /, ' ')
253
- if line_[0..3] == '### '
254
- line_.gsub!(/(\w)_(\w)/, '\1\_\2')
255
- end
256
- if line_[0..3] != ' '
257
- line_.gsub!('"it_should_behave_like"', '"it\_should\_behave\_like"')
258
- line_.gsub!('"time_zone"', '"time\_zone"')
259
- line_.gsub!(/\+(\w+)\+/, '`\1`')
260
- line_.gsub!(/\*(\w+)\*/, '**\1**')
261
- line_.gsub!(/<\/?em>/, '*')
262
- line_.gsub!(/<\/?tt>/, '`')
263
- line_.gsub!(/<\/?b>/, '**')
264
- line_.gsub!(/\{([^\}]+)\}\[([^\]]+)\]/) do |match_|
265
- text_, url_ = $1, $2
266
- "[#{text_.gsub('_', '\_')}](#{url_})"
267
- end
268
- line_.gsub!(/\ (http:\/\/[^\s]+)/, ' [\1](\1)')
269
- end
270
- write_.puts(line_)
271
- end
272
- end
273
- end
274
- end
@@ -1,140 +0,0 @@
1
- /*
2
- -----------------------------------------------------------------------------
3
-
4
- Blockenspiel unmixer (JRuby implementation)
5
-
6
- -----------------------------------------------------------------------------
7
- Copyright 2008-2009 Daniel Azuma
8
-
9
- 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
- * Redistributions of source code must retain the above copyright notice,
15
- this list of conditions and the following disclaimer.
16
- * Redistributions in binary form must reproduce the above copyright notice,
17
- this list of conditions and the following disclaimer in the documentation
18
- and/or other materials provided with the distribution.
19
- * Neither the name of the copyright holder, nor the names of any other
20
- contributors to this software, may be used to endorse or promote products
21
- derived from this software without specific prior written permission.
22
-
23
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33
- POSSIBILITY OF SUCH DAMAGE.
34
- -----------------------------------------------------------------------------
35
- */
36
-
37
-
38
- /*
39
- This implementation based on Mixology 0.1,
40
- written by Patrick Farley, anonymous z, Dan Manges, and Clint Bishop.
41
- http://rubyforge.org/projects/mixology
42
- http://github.com/dan-manges/mixology
43
-
44
- It has been stripped down and modified for JRuby 1.2 compatibility.
45
- */
46
-
47
- import java.io.IOException;
48
- import java.lang.reflect.InvocationTargetException;
49
- import java.lang.reflect.Method;
50
- import java.util.Iterator;
51
- import java.util.List;
52
- import java.util.ArrayList;
53
-
54
- import org.jruby.Ruby;
55
- import org.jruby.RubyArray;
56
- import org.jruby.RubyClass;
57
- import org.jruby.RubyModule;
58
- import org.jruby.anno.JRubyMethod;
59
- import org.jruby.IncludedModuleWrapper;
60
- import org.jruby.runtime.Block;
61
- import org.jruby.runtime.builtin.IRubyObject;
62
- import org.jruby.exceptions.RaiseException;
63
- import org.jruby.runtime.load.BasicLibraryService;
64
-
65
-
66
- public class BlockenspielUnmixerJrubyService implements BasicLibraryService
67
- {
68
-
69
- public boolean basicLoad(final Ruby runtime) throws IOException
70
- {
71
- RubyModule blockenspielModule = runtime.getOrCreateModule("Blockenspiel");
72
- RubyModule unmixerModule = runtime.defineModuleUnder("Unmixer", blockenspielModule);
73
- unmixerModule.getSingletonClass().defineAnnotatedMethods(BlockenspielUnmixerJrubyService.class);
74
- return true;
75
- }
76
-
77
-
78
- @JRubyMethod(name = "unmix", required = 2)
79
- public synchronized static IRubyObject unmix(IRubyObject self, IRubyObject receiver, IRubyObject module, Block block)
80
- throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
81
- {
82
- RubyModule actualModule = (RubyModule)module;
83
- RubyClass klass = receiver.getMetaClass();
84
- while (klass != receiver.getMetaClass().getRealClass())
85
- {
86
- RubyClass superClass = klass.getSuperClass();
87
- if (superClass != null && superClass.getNonIncludedClass() == actualModule)
88
- {
89
- if (actualModule.getSuperClass() != null &&
90
- actualModule.getSuperClass() instanceof IncludedModuleWrapper)
91
- {
92
- removeNestedModule(superClass, actualModule);
93
- }
94
- setSuperClass(klass, superClass.getSuperClass());
95
- invalidateCacheDescendants(klass);
96
- }
97
- klass = superClass;
98
- }
99
- return receiver;
100
- }
101
-
102
-
103
- protected synchronized static void removeNestedModule(RubyClass klass, RubyModule module)
104
- throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
105
- {
106
- if ((klass.getSuperClass() instanceof IncludedModuleWrapper) &&
107
- ((IncludedModuleWrapper)klass.getSuperClass()).getNonIncludedClass() ==
108
- ((IncludedModuleWrapper)module.getSuperClass()).getNonIncludedClass())
109
- {
110
- if (module.getSuperClass().getSuperClass() != null &&
111
- module.getSuperClass() instanceof IncludedModuleWrapper)
112
- {
113
- removeNestedModule(klass.getSuperClass(), module.getSuperClass());
114
- }
115
- setSuperClass(klass, klass.getSuperClass().getSuperClass());
116
- }
117
- }
118
-
119
-
120
- protected synchronized static void setSuperClass(RubyModule klass, RubyModule superClass)
121
- throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
122
- {
123
- Method method = RubyModule.class.getDeclaredMethod("setSuperClass",
124
- new Class[] {RubyClass.class} );
125
- method.setAccessible(true);
126
- Object[] superClassArg = new Object[] { superClass };
127
- method.invoke(klass, superClassArg);
128
- }
129
-
130
-
131
- protected synchronized static void invalidateCacheDescendants(RubyModule klass)
132
- throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
133
- {
134
- Method method = RubyModule.class.getDeclaredMethod("invalidateCacheDescendants", new Class[0]);
135
- method.setAccessible(true);
136
- method.invoke(klass, new Object[0]);
137
- }
138
-
139
- }
140
-