rkh-chainable 0.0.2

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.
Files changed (3) hide show
  1. data/LICENSE +27 -0
  2. data/README.rdoc +82 -0
  3. metadata +142 -0
data/LICENSE ADDED
@@ -0,0 +1,27 @@
1
+ copyright (c) 2009 Konstantin Haase. All rights reserved.
2
+
3
+ Developed by: Konstantin Haase
4
+ http://github.com/rkh/chainable
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to
8
+ deal with the Software without restriction, including without limitation the
9
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10
+ sell copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+ 1. Redistributions of source code must retain the above copyright notice,
13
+ this list of conditions and the following disclaimers.
14
+ 2. Redistributions in binary form must reproduce the above copyright
15
+ notice, this list of conditions and the following disclaimers in the
16
+ documentation and/or other materials provided with the distribution.
17
+ 3. Neither the name of Konstantin Haase, nor the names of other contributors
18
+ may be used to endorse or promote products derived from this Software without
19
+ specific prior written permission.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
27
+ WITH THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,82 @@
1
+ <b>A word of warning:</b>
2
+
3
+ This is heavy ruby abuse. It even got the Evil of the Day Award™ from zenspider.
4
+
5
+ == Thou shalt not use alias_method_chain!
6
+ - http://yehudakatz.com/2009/03/06/alias_method_chain-in-models
7
+ - http://yehudakatz.com/2009/01/18/other-ways-to-wrap-a-method
8
+ - http://www.codefluency.com/articles/2009/01/03/wrapping-a-method-in-ruby
9
+
10
+ == What it does
11
+ Chainable is an alternative to alias_method_chain, that uses inheritance, rather
12
+ than aliasing. It does the following when "chaining" a method:
13
+
14
+ - copy the original method to a new model
15
+ - include the model
16
+ - overwrite the method
17
+
18
+ Thus you can use super and keep your method list clean, too!
19
+ It even supports a (rather dangerous) auto chaining mode, so you do not have
20
+ to explicitly chain a method, but chain a method whenever it would be
21
+ overwritten instead.
22
+
23
+
24
+ Example:
25
+
26
+ class Foo
27
+
28
+ def foo
29
+ 10
30
+ end
31
+
32
+ # now chain to foo
33
+ chain_method :foo do
34
+ super + 3
35
+ end
36
+
37
+ # or turn on auto chaining
38
+ auto_chain do
39
+
40
+ def bar
41
+ 10
42
+ end
43
+
44
+ def bar
45
+ super + 1
46
+ end
47
+
48
+ def bar
49
+ super ** 2
50
+ end
51
+
52
+ end
53
+ end
54
+
55
+ f = Foo.new
56
+ puts f.foo # => 13
57
+ puts f.bar # => 121
58
+
59
+ Of course you can do this with any class (or module):
60
+
61
+ Array.class_eval do
62
+ chain_method :each
63
+ def each
64
+ return super if block_given? or RUBY_VERSION >= "1.8.7"
65
+ MyStuff::Enumerator.new self, :each
66
+ end
67
+ end
68
+
69
+ == Benchmark
70
+ chain_method tends do produce slightly faster methods than alias_method_chain:
71
+ user system total real
72
+ chainable (define_method) 0.160000 0.010000 0.170000 ( 0.183363)
73
+ chainable (def & eval) 0.170000 0.010000 0.180000 ( 0.177084)
74
+ alias_method_chain (define_method) 0.570000 0.030000 0.600000 ( 0.607330)
75
+ alias_method_chain (def & eval) 0.170000 0.020000 0.190000 ( 0.190048)
76
+
77
+ == Installation
78
+ Add github gems, if you haven't already:
79
+ gem sources -a http://gems.github.com
80
+
81
+ Install gem:
82
+ gem install rkh-chainable
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rkh-chainable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Konstantin Haase
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-20 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: never use alias_method_chain, again
17
+ email: konstantin.mailinglists@googlemail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ - LICENSE
25
+ files:
26
+ - tmp/rkh/chainable/lib/chainable.rb
27
+ - tmp/rkh/chainable/spec/chainable/chain_method_spec.rb
28
+ - tmp/rkh/chainable/spec/chainable/auto_chain_spec.rb
29
+ - tmp/rkh/chainable/benchmark/chainable.rb
30
+ - rack/lib/rack/cascade.rb
31
+ - rack/lib/rack/auth/digest/nonce.rb
32
+ - rack/lib/rack/auth/digest/md5.rb
33
+ - rack/lib/rack/auth/digest/request.rb
34
+ - rack/lib/rack/auth/digest/params.rb
35
+ - rack/lib/rack/auth/abstract/handler.rb
36
+ - rack/lib/rack/auth/abstract/request.rb
37
+ - rack/lib/rack/auth/openid.rb
38
+ - rack/lib/rack/auth/basic.rb
39
+ - rack/lib/rack/recursive.rb
40
+ - rack/lib/rack/response.rb
41
+ - rack/lib/rack/reloader.rb
42
+ - rack/lib/rack/urlmap.rb
43
+ - rack/lib/rack/commonlogger.rb
44
+ - rack/lib/rack/session/cookie.rb
45
+ - rack/lib/rack/session/abstract/id.rb
46
+ - rack/lib/rack/session/pool.rb
47
+ - rack/lib/rack/session/memcache.rb
48
+ - rack/lib/rack/lint.rb
49
+ - rack/lib/rack/showstatus.rb
50
+ - rack/lib/rack/showexceptions.rb
51
+ - rack/lib/rack/file.rb
52
+ - rack/lib/rack/mock.rb
53
+ - rack/lib/rack/builder.rb
54
+ - rack/lib/rack/lobster.rb
55
+ - rack/lib/rack/handler/mongrel.rb
56
+ - rack/lib/rack/handler/scgi.rb
57
+ - rack/lib/rack/handler/fastcgi.rb
58
+ - rack/lib/rack/handler/webrick.rb
59
+ - rack/lib/rack/handler/lsws.rb
60
+ - rack/lib/rack/handler/cgi.rb
61
+ - rack/lib/rack/adapter/camping.rb
62
+ - rack/lib/rack/request.rb
63
+ - rack/lib/rack/static.rb
64
+ - rack/lib/rack/utils.rb
65
+ - rack/lib/rack.rb
66
+ - rack/test/spec_rack_session_pool.rb
67
+ - rack/test/spec_rack_mongrel.rb
68
+ - rack/test/spec_rack_utils.rb
69
+ - rack/test/spec_rack_urlmap.rb
70
+ - rack/test/spec_rack_fastcgi.rb
71
+ - rack/test/spec_rack_showexceptions.rb
72
+ - rack/test/spec_rack_lint.rb
73
+ - rack/test/spec_rack_camping.rb
74
+ - rack/test/spec_rack_recursive.rb
75
+ - rack/test/spec_rack_webrick.rb
76
+ - rack/test/spec_rack_auth_digest.rb
77
+ - rack/test/spec_rack_file.rb
78
+ - rack/test/spec_rack_builder.rb
79
+ - rack/test/spec_rack_session_memcache.rb
80
+ - rack/test/spec_rack_mock.rb
81
+ - rack/test/spec_rack_lobster.rb
82
+ - rack/test/spec_rack_request.rb
83
+ - rack/test/spec_rack_auth_basic.rb
84
+ - rack/test/testrequest.rb
85
+ - rack/test/spec_rack_cgi.rb
86
+ - rack/test/spec_rack_showstatus.rb
87
+ - rack/test/spec_rack_session_cookie.rb
88
+ - rack/test/spec_rack_response.rb
89
+ - rack/test/spec_rack_static.rb
90
+ - rack/test/spec_rack_cascade.rb
91
+ - rack/test/spec_rack_commonlogger.rb
92
+ - rack/example/protectedlobster.rb
93
+ - sinatra/lib/sinatra/test/methods.rb
94
+ - sinatra/lib/sinatra/test/spec.rb
95
+ - sinatra/lib/sinatra/test/unit.rb
96
+ - sinatra/lib/sinatra.rb
97
+ - sinatra/test/use_in_file_templates_test.rb
98
+ - sinatra/test/app_test.rb
99
+ - sinatra/test/rest_test.rb
100
+ - sinatra/test/custom_error_test.rb
101
+ - sinatra/test/sym_params_test.rb
102
+ - sinatra/test/diddy_test.rb
103
+ - sinatra/test/template_test.rb
104
+ - sinatra/test/haml_test.rb
105
+ - sinatra/test/streaming_test.rb
106
+ - sinatra/test/erb_test.rb
107
+ - sinatra/test/event_context_test.rb
108
+ - sinatra/test/builder_test.rb
109
+ - sinatra/test/sass_test.rb
110
+ - sinatra/test/events_test.rb
111
+ - sinatra/test/mapped_error_test.rb
112
+ - sinatra/test/helper.rb
113
+ - sinatra/test/sessions_test.rb
114
+ - sinatra/test/application_test.rb
115
+ has_rdoc: true
116
+ homepage: http://rkh.github.com/chainable
117
+ post_install_message:
118
+ rdoc_options: []
119
+
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: "0"
127
+ version:
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: "0"
133
+ version:
134
+ requirements: []
135
+
136
+ rubyforge_project:
137
+ rubygems_version: 1.2.0
138
+ signing_key:
139
+ specification_version: 2
140
+ summary: never use alias_method_chain, again
141
+ test_files: []
142
+