rxcfc-proxy_block 0.1.1.1 → 0.1.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 (5) hide show
  1. data/README.textile +49 -0
  2. data/Rakefile +13 -0
  3. data/VERSION.yml +4 -0
  4. data/lib/proxy_block.rb +39 -0
  5. metadata +14 -11
data/README.textile ADDED
@@ -0,0 +1,49 @@
1
+ h1. ProxyBlock
2
+
3
+ h2. Overview
4
+
5
+ Simply modify methods that take a block to also provide a proxy
6
+
7
+
8
+ h2. Usage
9
+
10
+ h3. Example Classes
11
+
12
+ <pre><code>
13
+ class Wrapper
14
+
15
+ def hello
16
+ puts 'hello world'
17
+ end
18
+
19
+ def wrap(word = 'wrap')
20
+ puts "#{word} start"
21
+ yield
22
+ puts "#{word} end"
23
+ end
24
+ proxy_block :wrap
25
+
26
+ end
27
+ </code></pre>
28
+
29
+
30
+ h3. Standard behavior is maintained
31
+
32
+ <pre><code>
33
+ w = Wrapper.new
34
+ w.wrap{ w.hello }
35
+ # => wrap start
36
+ # => hello world
37
+ # => wrap end
38
+ </code></pre>
39
+
40
+
41
+ h3. Proxy Form
42
+
43
+ <pre><code>
44
+ w = Wrapper.new
45
+ w.wrap.hello
46
+ # => wrap start
47
+ # => hello world
48
+ # => wrap end
49
+ </code></pre>
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |gemspec|
4
+ gemspec.name = "proxy_block"
5
+ gemspec.summary = "Simply modify methods that take a block to also provide a proxy"
6
+ gemspec.email = "peter.wagenet@gmail.com"
7
+ gemspec.homepage = "http://github.com/rxcfc/proxy_block"
8
+ # gemspec.description = "TODO"
9
+ gemspec.authors = ["Peter Wagenet"]
10
+ end
11
+ rescue LoadError
12
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
13
+ end
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :patch: 2
3
+ :major: 0
4
+ :minor: 1
@@ -0,0 +1,39 @@
1
+ class Object
2
+ def proxy_block(method)
3
+ unless self.class.method_defined?("orig_#{method}")
4
+ alias_method "orig_#{method}", method
5
+ class_eval %{
6
+ def #{method}(*args, &block)
7
+ if block_given?
8
+ orig_#{method}(*args, &block)
9
+ else
10
+ BlockProxy.new(self, :orig_#{method}, *args)
11
+ end
12
+ end
13
+ }
14
+ end
15
+ end
16
+ end
17
+
18
+ class BlockProxy
19
+
20
+ # Make sure the proxy is as dumb as it can be.
21
+ # Blatanly taken from Jim Wierich's BlankSlate post:
22
+ # http://onestepback.org/index.cgi/Tech/Ruby/BlankSlate.rdoc
23
+ instance_methods.each { |m| undef_method m unless m =~ /^__/ }
24
+
25
+ def initialize(target, method, *args)
26
+ @target = target
27
+ @method = method
28
+ @args = args
29
+ end
30
+
31
+ def proxy_target; @target; end
32
+ def proxy_method; @method; end
33
+ def proxy_args; @args; end
34
+
35
+ def method_missing(method_name, *args, &block)
36
+ proxy_target.send(proxy_method, *proxy_args){ proxy_target.send(method_name, *args, &block) }
37
+ end
38
+
39
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rxcfc-proxy_block
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Wagenet
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-08 00:00:00 -07:00
12
+ date: 2009-04-23 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -19,15 +19,18 @@ executables: []
19
19
 
20
20
  extensions: []
21
21
 
22
- extra_rdoc_files: []
23
-
24
- files: []
25
-
26
- has_rdoc: false
27
- homepage: http://in.finitu.de
22
+ extra_rdoc_files:
23
+ - README.textile
24
+ files:
25
+ - README.textile
26
+ - Rakefile
27
+ - VERSION.yml
28
+ - lib/proxy_block.rb
29
+ has_rdoc: true
30
+ homepage: http://github.com/rxcfc/proxy_block
28
31
  post_install_message:
29
- rdoc_options: []
30
-
32
+ rdoc_options:
33
+ - --charset=UTF-8
31
34
  require_paths:
32
35
  - lib
33
36
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -47,7 +50,7 @@ requirements: []
47
50
  rubyforge_project:
48
51
  rubygems_version: 1.2.0
49
52
  signing_key:
50
- specification_version: 2
53
+ specification_version: 3
51
54
  summary: Simply modify methods that take a block to also provide a proxy
52
55
  test_files: []
53
56