dslkit 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,2 +1,5 @@
1
+ 2007-02-22 (0.2.1)
2
+ * Add coverage to tests.
3
+ * New delegate method for classes/modules.
1
4
  2006-09-22 (0.2.0)
2
5
  * Initial Released Version
data/Rakefile CHANGED
@@ -22,9 +22,14 @@ task :test do
22
22
  ruby '-Ilib tests/runner.rb'
23
23
  end
24
24
 
25
+ desc "Testing library with coverage"
26
+ task :coverage do
27
+ system 'rcov -Ilib tests/test_rude.rb'
28
+ end
29
+
25
30
  desc "Clean created files"
26
31
  task :clean do
27
- %w[doc coverage].each { |file| rm_r file, :force => true }
32
+ rm_rf %w[doc coverage]
28
33
  end
29
34
 
30
35
  desc "Prepare a release"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -535,4 +535,47 @@ module DSLKit
535
535
  Thread.critical = old
536
536
  end
537
537
  end
538
+
539
+ # This module can be included into modules/classes to make the delegate
540
+ # method available.
541
+ module Delegate
542
+ # A method to easily delegate methods to an object, stored in an
543
+ # instance variable or returned by a method call.
544
+ #
545
+ # It's used like this:
546
+ # class A
547
+ # delegate :method_here, :@obj, :method_there
548
+ # end
549
+ # or:
550
+ # class A
551
+ # delegate :method_here, :method_call, :method_there
552
+ # end
553
+ #
554
+ # _other_method_name_ defaults to method_name, if it wasn't given.
555
+ def delegate(method_name, obj, other_method_name = method_name)
556
+ raise ArgumentError, "obj wasn't defined" unless obj
557
+ =begin
558
+ 1.9 only:
559
+ define_method(method_name) do |*args, &block|
560
+ instance_variable_get(obj).__send__(other_method_name, *args, &block)
561
+ end
562
+ =end
563
+ obj = obj.to_s
564
+ if obj[0] == ?@
565
+ class_eval <<-EOS
566
+ def #{method_name}(*args, &block)
567
+ instance_variable_get('#{obj}').__send__(
568
+ '#{other_method_name}', *args, &block)
569
+ end
570
+ EOS
571
+ else
572
+ class_eval <<-EOS
573
+ def #{method_name}(*args, &block)
574
+ __send__('#{obj}').__send__(
575
+ '#{other_method_name}', *args, &block)
576
+ end
577
+ EOS
578
+ end
579
+ end
580
+ end
538
581
  end
@@ -9,6 +9,7 @@ module DSLKit
9
9
  include DSLKit::Constant
10
10
  include DSLKit::DSLAccessor
11
11
  include DSLKit::ClassMethod
12
+ include DSLKit::Delegate
12
13
  end
13
14
 
14
15
  class ::Object
@@ -177,4 +177,12 @@ class TC_DSLKit < Test::Unit::TestCase
177
177
  assert !D.deflect?(Integer, :method_missing)
178
178
  assert_raises(NoMethodError) { 1.foo }
179
179
  end
180
+
181
+ def test_delegate
182
+ d = D2.new
183
+ assert_equal 3, d.my_size1
184
+ assert_equal 3, d.my_size2
185
+ assert_equal 3, d.size
186
+ assert_equal 3, d.length
187
+ end
180
188
  end
@@ -88,4 +88,18 @@ module D
88
88
  extend DSLKit::Deflect
89
89
  end
90
90
 
91
+ class D2
92
+ extend DSLKit::Delegate
93
+
94
+ def initialize
95
+ @ary = [ 1, 2, 3 ]
96
+ end
97
+ attr_reader :ary
98
+
99
+ delegate :my_size1, :@ary, :size
100
+ delegate :my_size2, :ary, :size
101
+ delegate :size, :ary
102
+ delegate :length, :ary
103
+ end
104
+
91
105
  require 'test_common'
@@ -67,4 +67,16 @@ end
67
67
  module D
68
68
  end
69
69
 
70
+ class D2
71
+ def initialize
72
+ @ary = [ 1, 2, 3 ]
73
+ end
74
+ attr_reader :ary
75
+
76
+ delegate :my_size1, :@ary, :size
77
+ delegate :my_size2, :ary, :size
78
+ delegate :size, :@ary
79
+ delegate :length, :ary
80
+ end
81
+
70
82
  require 'test_common'
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.11
2
+ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: dslkit
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.0
7
- date: 2006-09-22 00:00:00 +02:00
6
+ version: 0.2.1
7
+ date: 2007-02-22 00:00:00 +01:00
8
8
  summary: Kit for building DSLs in Ruby
9
9
  require_paths:
10
10
  - lib
@@ -25,6 +25,7 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
25
25
  platform: ruby
26
26
  signing_key:
27
27
  cert_chain:
28
+ post_install_message:
28
29
  authors:
29
30
  - Florian Frank
30
31
  files: