prox 0.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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +6 -0
- data/lib/prox.rb +34 -0
- data/lib/prox/version.rb +5 -0
- data/prox.gemspec +23 -0
- data/test/prox_test.rb +98 -0
- data/test/test_helper.rb +3 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 30fb5a2f22e001a5af7da05f7e785bcb376252c2
|
4
|
+
data.tar.gz: c718d02abd63070f21f7e7de7eae208ce69e0171
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 52083a4ca664b2c0b16228023fcb438d302e4cf76698db185a5e6a1d6ef1cbf0632c9159110ba9481dec39568c4595776dede208b58f5a548af7db07dedd6765
|
7
|
+
data.tar.gz: 2d4fded2818c245b8dcf18f3dbb02ddcdd4fa4df2a99717630164409d9479f4126c86d721beb71803ff6a5172d5ee44f95e1ad4235101e5e844f5793fd74430b
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 ahawkins
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Prox
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'prox'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install prox
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/prox.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require "prox/version"
|
2
|
+
require 'delegate'
|
3
|
+
|
4
|
+
class Prox < ::SimpleDelegator
|
5
|
+
class MissingObject < StandardError
|
6
|
+
def initialize(message)
|
7
|
+
@message = message
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_s
|
11
|
+
"Cannot send #{@message} without a __getobj__ object!"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
alias __proxy_class__ class
|
16
|
+
|
17
|
+
def is_a?(klass)
|
18
|
+
__getobj__.is_a? klass
|
19
|
+
end
|
20
|
+
alias kind_of? is_a?
|
21
|
+
|
22
|
+
def instance_of?(klass)
|
23
|
+
__getobj__.instance_of? klass
|
24
|
+
end
|
25
|
+
|
26
|
+
def class
|
27
|
+
__getobj__.class
|
28
|
+
end
|
29
|
+
|
30
|
+
def method_missing(name, *args, &block)
|
31
|
+
raise MissingObject, name unless __getobj__
|
32
|
+
__getobj__.send name, *args, &block
|
33
|
+
end
|
34
|
+
end
|
data/lib/prox/version.rb
ADDED
data/prox.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'prox/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "prox"
|
8
|
+
spec.version = Prox::VERSION
|
9
|
+
spec.authors = ["ahawkins"]
|
10
|
+
spec.email = ["adam@hawkins.io"]
|
11
|
+
spec.description = %q{Transparent object proxy based on SimpleDelegator}
|
12
|
+
spec.summary = %q{}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
data/test/prox_test.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
class ProxTest < MiniTest::Unit::TestCase
|
4
|
+
Person = Struct.new(:name, :id) do
|
5
|
+
def ==(other)
|
6
|
+
other.instance_of?(self.class) && id == other.id
|
7
|
+
end
|
8
|
+
|
9
|
+
def eql?(other)
|
10
|
+
self == other
|
11
|
+
end
|
12
|
+
|
13
|
+
def method_missing(name, *args, &block)
|
14
|
+
if name == :secret_method
|
15
|
+
'bar'
|
16
|
+
else
|
17
|
+
super
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_fowards_messages_to_the_content
|
23
|
+
proxy = Prox.new Person.new('Adam')
|
24
|
+
|
25
|
+
assert_equal proxy.name, 'Adam'
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_proxies_methods_implemented_with_method_missing
|
29
|
+
proxy = Prox.new Person.new('Adam')
|
30
|
+
|
31
|
+
assert_equal 'bar', proxy.secret_method
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_raises_an_error_on_undefined_methods
|
35
|
+
proxy = Prox.new Person.new
|
36
|
+
|
37
|
+
assert_raises NoMethodError do
|
38
|
+
proxy.hobby
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_raises_an_error_when_no_content
|
43
|
+
proxy = Prox.new nil
|
44
|
+
|
45
|
+
assert_raises Prox::MissingObject do
|
46
|
+
proxy.hi
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_proxy_completely_imitate_reflection_interface
|
51
|
+
proxy = Prox.new Person.new('Adam')
|
52
|
+
|
53
|
+
assert proxy.is_a?(Person)
|
54
|
+
assert proxy.kind_of?(Person)
|
55
|
+
assert proxy.instance_of?(Person)
|
56
|
+
assert_equal Person, proxy.class
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_equality
|
60
|
+
a = Person.new 'Adam', 'ahawkins'
|
61
|
+
b = Person.new 'Paul', 'pcowan'
|
62
|
+
c = Person.new 'Adam', 'ahawkins'
|
63
|
+
|
64
|
+
assert_equal a, c, "Precondition: objects must be equal"
|
65
|
+
assert_equal c, a, "Precondition: objects must be equal"
|
66
|
+
refute_equal a, b, "Precondition: objects must not be equal"
|
67
|
+
refute_equal b, a, "Precondition: objects must not be equal"
|
68
|
+
|
69
|
+
assert a.eql?(c), "Precondition: objects must be equal"
|
70
|
+
assert c.eql?(a), "Precondition: objects must be equal"
|
71
|
+
refute a.eql?(b), "Precondition: objects must not be equal"
|
72
|
+
refute b.eql?(a), "Precondition: objects must not be equal"
|
73
|
+
|
74
|
+
pa = Prox.new a
|
75
|
+
pb = Prox.new b
|
76
|
+
pc = Prox.new c
|
77
|
+
|
78
|
+
assert_equal pa, pc
|
79
|
+
assert_equal pc, pa
|
80
|
+
refute_equal pa, pb
|
81
|
+
refute_equal pb, pa
|
82
|
+
|
83
|
+
assert pa.eql?(pc)
|
84
|
+
assert pc.eql?(pa)
|
85
|
+
refute pa.eql?(pb)
|
86
|
+
refute pb.eql?(pa)
|
87
|
+
|
88
|
+
assert_equal pa, c
|
89
|
+
assert_equal pc, a
|
90
|
+
refute_equal pa, b
|
91
|
+
refute_equal pb, a
|
92
|
+
|
93
|
+
assert pa.eql?(c)
|
94
|
+
assert pc.eql?(a)
|
95
|
+
refute pa.eql?(b)
|
96
|
+
refute pb.eql?(a)
|
97
|
+
end
|
98
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: prox
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ahawkins
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Transparent object proxy based on SimpleDelegator
|
42
|
+
email:
|
43
|
+
- adam@hawkins.io
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- lib/prox.rb
|
54
|
+
- lib/prox/version.rb
|
55
|
+
- prox.gemspec
|
56
|
+
- test/prox_test.rb
|
57
|
+
- test/test_helper.rb
|
58
|
+
homepage: ''
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata: {}
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 2.0.3
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: ''
|
82
|
+
test_files:
|
83
|
+
- test/prox_test.rb
|
84
|
+
- test/test_helper.rb
|