fast_forward 1.0.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.txt ADDED
@@ -0,0 +1,3 @@
1
+ == 1.0.0 / 2007-05-12
2
+
3
+ * Initial release
data/README.txt ADDED
@@ -0,0 +1,90 @@
1
+ fast_forward
2
+ http://codefluency.rubyforge.org/fast_forward
3
+ Bruce Williams
4
+
5
+ == DESCRIPTION:
6
+
7
+ fast_forward is a small library designed to do two things:
8
+ * Allow easy delegation of all missing methods to an accessor/instance variable
9
+ * Generate methods on-the-fly after first invocation of a delegated method to
10
+ eliminate the need to search the object's ancestors and use method_missing
11
+ on subsequent invocations
12
+
13
+ == FEATURES/PROBLEMS:
14
+
15
+ == SYNOPSIS:
16
+
17
+ To forward all missing methods to an object, use the <tt>fast_forward_to</tt> class method, as in this example:
18
+
19
+ class Foo
20
+ def some_foo_method
21
+ "Hello"
22
+ end
23
+ end
24
+
25
+ class Bar
26
+ fast_forward_to :my_foo
27
+ attr_reader :my_foo
28
+ def initialize
29
+ @my_foo = Foo.new
30
+ end
31
+ end
32
+
33
+ Now, if I create a <tt>Bar</tt> instance, I can call <tt>Foo#some_foo_method</tt> transparently using <tt>Bar#some_foo_method</tt>:
34
+
35
+ bar = Bar.new
36
+ bar.some_foo_method
37
+ => "Hello"
38
+
39
+ Note I could have also set the forwarding in this example using an instance variable instead of the accessor:
40
+
41
+ class Bar
42
+ fast_forward_to :@my_foo
43
+ # the initialize, etc
44
+ end
45
+
46
+ ... and it would have worked the same.
47
+
48
+ The cool feature with this setup is the fact that, one you call a method that gets delegated once on an object, a method to do the delegation is added to the object so performance is better in subsequent invocations:
49
+
50
+ bar = Bar.new
51
+ bar.respond_to?(:some_foo_method)
52
+ => false
53
+ bar.some_foo_method
54
+ => "Hello"
55
+ bar.respond_to?(:some_foo_method)
56
+ => true
57
+
58
+ == REQUIREMENTS:
59
+
60
+ * activesupport (1.4.2 minimum, though previous versions will likely work), installed if you have Rails
61
+ * hoe
62
+
63
+ == INSTALL:
64
+
65
+ * sudo gem install
66
+
67
+ == LICENSE:
68
+
69
+ (The MIT License)
70
+
71
+ Copyright (c) 2007 Bruce Williams
72
+
73
+ Permission is hereby granted, free of charge, to any person obtaining
74
+ a copy of this software and associated documentation files (the
75
+ 'Software'), to deal in the Software without restriction, including
76
+ without limitation the rights to use, copy, modify, merge, publish,
77
+ distribute, sublicense, and/or sell copies of the Software, and to
78
+ permit persons to whom the Software is furnished to do so, subject to
79
+ the following conditions:
80
+
81
+ The above copyright notice and this permission notice shall be
82
+ included in all copies or substantial portions of the Software.
83
+
84
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
85
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
86
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
87
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
88
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
89
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
90
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,25 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+
4
+ module FastForwarding
5
+
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}
13
+ end
14
+ DELEGATION_GENERATION
15
+ end
16
+ end
17
+ METHOD_MISSING_GENERATION
18
+ alias_method_chain :method_missing, :fast_forwarding
19
+ end
20
+
21
+ end
22
+
23
+ class Class
24
+ include FastForwarding
25
+ end
@@ -0,0 +1,61 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/fast_forward'
3
+
4
+ class Target
5
+ def a_method_that_exists
6
+ :expected_return_value
7
+ end
8
+ end
9
+
10
+ class FastForwarded
11
+ fast_forward_to :target
12
+ attr_reader :target
13
+ def initialize
14
+ @target = Target.new
15
+ end
16
+ end
17
+
18
+ class FastForwardUsingInstanceVar
19
+ fast_forward_to :@target
20
+ def initialize
21
+ @target = Target.new
22
+ end
23
+ end
24
+
25
+
26
+ class NotFastForwarded
27
+ end
28
+
29
+ class FastForwardTest < Test::Unit::TestCase
30
+
31
+ attr_reader :fast_forwarded
32
+ def setup
33
+ @fast_forwarded = FastForwarded.new
34
+ end
35
+
36
+ def test_calling_a_method_on_a_fast_forwarded_instance_may_be_forwarded_to_target_object
37
+ assert !fast_forwarded.respond_to?(:a_method_that_exists)
38
+ assert_equal :expected_return_value, fast_forwarded.a_method_that_exists
39
+ end
40
+
41
+ def test_calling_a_method_on_a_fast_forwarded_instance_may_be_forwarded_to_target_object_using_instance_var
42
+ fast_forward_with_instance_var = FastForwardUsingInstanceVar.new
43
+ assert !fast_forward_with_instance_var.respond_to?(:a_method_that_exists)
44
+ assert_equal :expected_return_value, fast_forward_with_instance_var.a_method_that_exists
45
+ end
46
+
47
+ def test_second_call_to_fast_forwarded_method_does_not_use_method_missing
48
+ assert !fast_forwarded.respond_to?(:a_method_that_exists)
49
+ fast_forwarded.a_method_that_exists
50
+ assert fast_forwarded.respond_to?(:a_method_that_exists)
51
+ end
52
+
53
+ def test_call_to_fast_forwarded_method_does_not_affect_other_instances_of_same_class
54
+ assert !fast_forwarded.respond_to?(:a_method_that_exists)
55
+ fast_forwarded.a_method_that_exists
56
+ assert fast_forwarded.respond_to?(:a_method_that_exists)
57
+ another_fast_forward = FastForwarded.new
58
+ assert !another_fast_forward.respond_to?(:a_method_that_exists)
59
+ end
60
+
61
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.0
3
+ specification_version: 1
4
+ name: fast_forward
5
+ version: !ruby/object:Gem::Version
6
+ version: 1.0.0
7
+ date: 2007-05-13 00:00:00 -06:00
8
+ summary: Advanced delegation of method missing with dynamic generation of methods to reduce overhead
9
+ require_paths:
10
+ - lib
11
+ email: bruce@codefluency.com
12
+ homepage: " http://codefluency.rubyforge.org/fast_forward"
13
+ rubyforge_project: codefluency
14
+ description: "fast_forward is a small library designed to do two things: * Allow easy delegation of all missing methods to an accessor/instance variable * Generate methods on-the-fly after first invocation of a delegated method to eliminate the need to search the object's ancestors and use method_missing on subsequent invocations"
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Bruce Williams
31
+ files:
32
+ - History.txt
33
+ - README.txt
34
+ - lib/fast_forward.rb
35
+ - test/test_fast_forward.rb
36
+ test_files:
37
+ - test/test_fast_forward.rb
38
+ rdoc_options: []
39
+
40
+ extra_rdoc_files: []
41
+
42
+ executables: []
43
+
44
+ extensions: []
45
+
46
+ requirements: []
47
+
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
+ - !ruby/object:Gem::Dependency
59
+ name: hoe
60
+ version_requirement:
61
+ version_requirements: !ruby/object:Gem::Version::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: 1.2.0
66
+ version: