zeevex_proxy 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/Rakefile +32 -0
- data/lib/zeevex_proxy/base.rb +42 -0
- data/lib/zeevex_proxy/version.rb +3 -0
- data/lib/zeevex_proxy.rb +4 -0
- data/spec/proxy_base_spec.rb +102 -0
- data/spec/spec_helper.rb +5 -0
- data/zeevex_proxy.gemspec +24 -0
- metadata +98 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use ree@zeevex_gems --create
|
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
|
6
|
+
|
7
|
+
RSpec::Core::RakeTask.new(:spec)
|
8
|
+
|
9
|
+
namespace :spec do
|
10
|
+
desc "Run on three Rubies"
|
11
|
+
task :platforms do
|
12
|
+
current = %x{rvm-prompt v}
|
13
|
+
|
14
|
+
fail = false
|
15
|
+
%w{1.8.7 1.9.3 ree}.each do |version|
|
16
|
+
puts "Switching to #{version}"
|
17
|
+
Bundler.with_clean_env do
|
18
|
+
system %{bash -c 'source ~/.rvm/scripts/rvm && rvm #{version} && bundle exec rake spec'}
|
19
|
+
end
|
20
|
+
if $?.exitstatus != 0
|
21
|
+
fail = true
|
22
|
+
break
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
system %{rvm #{current}}
|
27
|
+
|
28
|
+
exit (fail ? 1 : 0)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
task :default => 'spec:platforms'
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module ZeevexProxy
|
2
|
+
if defined? ::BasicObject
|
3
|
+
# A class with no predefined methods that behaves similarly to Builder's
|
4
|
+
# BlankSlate. Used for proxy classes.
|
5
|
+
class BasicObject < ::BasicObject
|
6
|
+
undef_method :==
|
7
|
+
undef_method :equal?
|
8
|
+
|
9
|
+
# Let ActiveSupport::BasicObject at least raise exceptions.
|
10
|
+
def raise(*args)
|
11
|
+
::Object.send(:raise, *args)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
else
|
15
|
+
class BasicObject
|
16
|
+
KEEP_METHODS = %w"__id__ __send__ method_missing"
|
17
|
+
|
18
|
+
def self.remove_methods!
|
19
|
+
m = (instance_methods) - KEEP_METHODS
|
20
|
+
m.each{|m| undef_method(m)}
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(*args)
|
24
|
+
BasicObject.remove_methods!
|
25
|
+
end
|
26
|
+
|
27
|
+
BasicObject.remove_methods!
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class Base < BasicObject
|
32
|
+
def initialize(target, options = {})
|
33
|
+
super
|
34
|
+
@obj = target
|
35
|
+
end
|
36
|
+
|
37
|
+
def method_missing(name, *args, &block)
|
38
|
+
@obj.__send__(name, *args, &block)
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
data/lib/zeevex_proxy.rb
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
|
+
|
4
|
+
# Be sure to include AuthenticatedTestHelper in spec/spec_helper.rb instead.
|
5
|
+
# Then, you can remove it from this and the functional test.
|
6
|
+
|
7
|
+
describe ZeevexProxy::Base do
|
8
|
+
class Responder
|
9
|
+
def responder_method
|
10
|
+
"itsa me"
|
11
|
+
end
|
12
|
+
|
13
|
+
def called_with_block?
|
14
|
+
block_given?
|
15
|
+
end
|
16
|
+
|
17
|
+
def block_call
|
18
|
+
yield
|
19
|
+
end
|
20
|
+
|
21
|
+
# expected to be defined on Object
|
22
|
+
def to_enum
|
23
|
+
"this is not an enum"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
before(:each) do
|
28
|
+
Object.class_eval do
|
29
|
+
def responder_method
|
30
|
+
"shouldn't see this one"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class ProxyClass < ZeevexProxy::Base; end
|
35
|
+
end
|
36
|
+
|
37
|
+
after(:each) do
|
38
|
+
Object.send :undef_method, :responder_method
|
39
|
+
end
|
40
|
+
|
41
|
+
let :object do
|
42
|
+
Responder.new
|
43
|
+
end
|
44
|
+
|
45
|
+
let :proxy do
|
46
|
+
ProxyClass.new object
|
47
|
+
end
|
48
|
+
|
49
|
+
context "hygiene" do
|
50
|
+
it "should not have instance methods previously defined on Object" do
|
51
|
+
ProxyClass.instance_methods.should_not include(:responder_method)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "instance identity" do
|
56
|
+
subject { proxy }
|
57
|
+
it "identifies as an instance of its proxy target" do
|
58
|
+
proxy.should be_instance_of(Responder)
|
59
|
+
end
|
60
|
+
it "returns Responder as the class" do
|
61
|
+
proxy.class.should == Responder
|
62
|
+
end
|
63
|
+
it "responds_to a defined method on Responder" do
|
64
|
+
proxy.should respond_to(:responder_method)
|
65
|
+
end
|
66
|
+
it "has the same object_id as the proxy target" do
|
67
|
+
proxy.object_id.should == object.object_id
|
68
|
+
end
|
69
|
+
it "should return methods" do
|
70
|
+
proxy.method(:responder_method).should == object.method(:responder_method)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context "proxying to object" do
|
75
|
+
subject { object }
|
76
|
+
it "should receive stub messages with arguments called on the proxy" do
|
77
|
+
object.should_receive(:foo).with(5).and_return(100)
|
78
|
+
proxy.foo(5).should == 100
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should receive messages called with :send on the proxy" do
|
82
|
+
object.should_receive(:foo).and_return(200)
|
83
|
+
proxy.send(:foo).should == 200
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should call the target's method for a method defined in Object" do
|
87
|
+
proxy.to_enum.should == "this is not an enum"
|
88
|
+
end
|
89
|
+
|
90
|
+
# the Object methods are undef'd at the time BasicObject is defined; anything loaded
|
91
|
+
# after that may add methods to Object which will not be passed to method_missing, and
|
92
|
+
# this not proxied to the target.
|
93
|
+
it "should call the target's method for a method defined in Object *after* proxy creation" do
|
94
|
+
proxy.responder_method.should == "itsa me"
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should pass along blocks to proxy methods" do
|
98
|
+
proxy.called_with_block? { nil }.should == true
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "zeevex_proxy/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "zeevex_proxy"
|
7
|
+
s.version = ZeevexProxy::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Robert Sanders"]
|
10
|
+
s.email = ["robert@zeevex.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{Our homegrown version of a Proxy object}
|
13
|
+
s.description = %q{This is a Proxy object; there are many others like it, but this one is ours.}
|
14
|
+
|
15
|
+
s.rubyforge_project = "zeevex_proxy"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_development_dependency 'rspec', '~> 2.9.0'
|
23
|
+
s.add_development_dependency 'rake'
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zeevex_proxy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 9
|
8
|
+
- 0
|
9
|
+
version: 0.9.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Robert Sanders
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2012-05-02 00:00:00 -04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 2
|
29
|
+
- 9
|
30
|
+
- 0
|
31
|
+
version: 2.9.0
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rake
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
type: :development
|
45
|
+
version_requirements: *id002
|
46
|
+
description: This is a Proxy object; there are many others like it, but this one is ours.
|
47
|
+
email:
|
48
|
+
- robert@zeevex.com
|
49
|
+
executables: []
|
50
|
+
|
51
|
+
extensions: []
|
52
|
+
|
53
|
+
extra_rdoc_files: []
|
54
|
+
|
55
|
+
files:
|
56
|
+
- .gitignore
|
57
|
+
- .rvmrc
|
58
|
+
- Gemfile
|
59
|
+
- Rakefile
|
60
|
+
- lib/zeevex_proxy.rb
|
61
|
+
- lib/zeevex_proxy/base.rb
|
62
|
+
- lib/zeevex_proxy/version.rb
|
63
|
+
- spec/proxy_base_spec.rb
|
64
|
+
- spec/spec_helper.rb
|
65
|
+
- zeevex_proxy.gemspec
|
66
|
+
has_rdoc: true
|
67
|
+
homepage: ""
|
68
|
+
licenses: []
|
69
|
+
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
89
|
+
requirements: []
|
90
|
+
|
91
|
+
rubyforge_project: zeevex_proxy
|
92
|
+
rubygems_version: 1.3.6
|
93
|
+
signing_key:
|
94
|
+
specification_version: 3
|
95
|
+
summary: Our homegrown version of a Proxy object
|
96
|
+
test_files:
|
97
|
+
- spec/proxy_base_spec.rb
|
98
|
+
- spec/spec_helper.rb
|