fast_forward 1.0.0 → 1.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/README.txt CHANGED
@@ -54,10 +54,11 @@ The cool feature with this setup is the fact that, one you call a method that ge
54
54
  => "Hello"
55
55
  bar.respond_to?(:some_foo_method)
56
56
  => true
57
+
58
+ If the target of <tt>fast_forward_to</tt> is <tt>nil</tt>, a FastForwarding::DelegationToNilError will be raised any time a method that would use the delegation is invoked.
57
59
 
58
60
  == REQUIREMENTS:
59
61
 
60
- * activesupport (1.4.2 minimum, though previous versions will likely work), installed if you have Rails
61
62
  * hoe
62
63
 
63
64
  == INSTALL:
@@ -1,21 +1,35 @@
1
- require 'rubygems'
2
- require 'active_support'
3
-
4
1
  module FastForwarding
2
+
3
+ class DelegationToNilError < ::NoMethodError; end
4
+
5
+ class << self
6
+
7
+ def included(base)
8
+ base.send(:include, InstanceMethods)
9
+ end
10
+
11
+ end
12
+
13
+ module InstanceMethods
5
14
 
6
- def fast_forward_to(object)
7
- class_eval <<-METHOD_MISSING_GENERATION
8
- def method_missing_with_fast_forwarding(meth, *args, &block)
9
- returning #{object}.__send__(meth, *args, &block) do
10
- instance_eval <<-DELEGATION_GENERATION
11
- class << self
12
- delegate :\#{meth}, :to => :#{object}
15
+ def fast_forward_to(object)
16
+ class_eval(<<-END_OF_METHOD_MISSING, "(__FAST_FORWARD__)", 1)
17
+ def method_missing_with_fast_forwarding(meth, *args, &block)
18
+ raise FastForwarding::DelegationToNilError, "Cannot delegate to nil: #{object}" if #{object}.nil?
19
+ result = #{object}.__send__(meth, *args, &block)
20
+ (class << self; self; end).module_eval(<<-EOS, "(__FAST_FORWARD_GENERATE_METHOD__)", 1)
21
+ def \#{meth}(*args, &block)
22
+ raise FastForwarding::DelegationToNilError, "Cannot delegate to nil: #{object}" if #{object}.nil?
23
+ #{object}.__send__(:\#{meth}, *args, &block)
13
24
  end
14
- DELEGATION_GENERATION
25
+ EOS
26
+ result
15
27
  end
16
- end
17
- METHOD_MISSING_GENERATION
18
- alias_method_chain :method_missing, :fast_forwarding
28
+ alias_method :method_missing_without_fast_forwarding, :method_missing
29
+ alias_method :method_missing, :method_missing_with_fast_forwarding
30
+ END_OF_METHOD_MISSING
31
+ end
32
+
19
33
  end
20
34
 
21
35
  end
@@ -9,7 +9,7 @@ end
9
9
 
10
10
  class FastForwarded
11
11
  fast_forward_to :target
12
- attr_reader :target
12
+ attr_accessor :target
13
13
  def initialize
14
14
  @target = Target.new
15
15
  end
@@ -38,6 +38,25 @@ class FastForwardTest < Test::Unit::TestCase
38
38
  assert_equal :expected_return_value, fast_forwarded.a_method_that_exists
39
39
  end
40
40
 
41
+ def test_calling_a_method_the_first_time_on_a_fast_forwarded_instance_when_target_object_is_nil_raises_delegation_to_nil_error
42
+ assert !fast_forwarded.respond_to?(:a_method_that_exists)
43
+ fast_forwarded.target = nil
44
+ assert_raises FastForwarding::DelegationToNilError do
45
+ fast_forwarded.a_method_that_exists
46
+ end
47
+ assert !fast_forwarded.respond_to?(:a_method_that_exists)
48
+ end
49
+
50
+ def test_calling_a_method_subsequent_times_on_a_fast_forwarded_instance_when_target_object_is_nil_raises_delegation_to_nil_error
51
+ assert !fast_forwarded.respond_to?(:a_method_that_exists)
52
+ assert_equal :expected_return_value, fast_forwarded.a_method_that_exists
53
+ assert fast_forwarded.respond_to?(:a_method_that_exists)
54
+ fast_forwarded.target = nil
55
+ assert_raises FastForwarding::DelegationToNilError do
56
+ fast_forwarded.a_method_that_exists
57
+ end
58
+ end
59
+
41
60
  def test_calling_a_method_on_a_fast_forwarded_instance_may_be_forwarded_to_target_object_using_instance_var
42
61
  fast_forward_with_instance_var = FastForwardUsingInstanceVar.new
43
62
  assert !fast_forward_with_instance_var.respond_to?(:a_method_that_exists)
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: fast_forward
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.0
7
- date: 2007-05-13 00:00:00 -06:00
6
+ version: 1.0.1
7
+ date: 2007-05-14 00:00:00 -06:00
8
8
  summary: Advanced delegation of method missing with dynamic generation of methods to reduce overhead
9
9
  require_paths:
10
10
  - lib
@@ -46,15 +46,6 @@ extensions: []
46
46
  requirements: []
47
47
 
48
48
  dependencies:
49
- - !ruby/object:Gem::Dependency
50
- name: activesupport
51
- version_requirement:
52
- version_requirements: !ruby/object:Gem::Version::Requirement
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- version: 1.4.2
57
- version:
58
49
  - !ruby/object:Gem::Dependency
59
50
  name: hoe
60
51
  version_requirement: