proxify 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +13 -0
- data/lib/proxify.rb +3 -0
- data/lib/proxify/proxify.rb +53 -0
- data/lib/proxify/version.rb +3 -0
- data/proxify.gemspec +19 -0
- data/spec/proxy_spec.rb +74 -0
- data/spec/spec_helper.rb +19 -0
- metadata +66 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Robbie Clutton
|
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
|
+
# Proxy
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'proxy'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install proxy
|
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/proxify.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
module Proxify
|
2
|
+
|
3
|
+
class Proxy
|
4
|
+
|
5
|
+
attr_reader :subject, :proxies
|
6
|
+
|
7
|
+
def initialize(subject, proxies)
|
8
|
+
@subject = subject
|
9
|
+
@proxies = proxies
|
10
|
+
end
|
11
|
+
|
12
|
+
def method_missing(method, *args, &block)
|
13
|
+
if proxies.include?(method)
|
14
|
+
return subject.send(method, *args, &block)
|
15
|
+
else
|
16
|
+
raise NoMethodError, method.to_s
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module ProxifyClass
|
22
|
+
attr_accessor :proxies
|
23
|
+
|
24
|
+
def proxy(*args)
|
25
|
+
@proxies = args
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
module Me
|
30
|
+
extend Proxify::ProxifyClass
|
31
|
+
|
32
|
+
def self.included(base)
|
33
|
+
base.send :extend, Proxify::ProxifyClass
|
34
|
+
end
|
35
|
+
|
36
|
+
def proxy
|
37
|
+
class_name = "#{self.class.name}Proxy"
|
38
|
+
klass = if k = class_exists?(class_name)
|
39
|
+
k
|
40
|
+
else
|
41
|
+
Object.const_set(class_name, Proxy)
|
42
|
+
end
|
43
|
+
|
44
|
+
klass.new(self, self.class.proxies)
|
45
|
+
end
|
46
|
+
|
47
|
+
def class_exists?(class_name)
|
48
|
+
Object.const_get(class_name)
|
49
|
+
rescue NameError
|
50
|
+
return false
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/proxify.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'proxify/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "proxify"
|
8
|
+
gem.version = Proxify::VERSION
|
9
|
+
gem.authors = ["Robbie Clutton"]
|
10
|
+
gem.email = ["hello@iclutton.com"]
|
11
|
+
gem.description = %q{Create a proxy for any object.}
|
12
|
+
gem.summary = %q{Create a proxy for any object.}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
end
|
data/spec/proxy_spec.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class Proxied
|
4
|
+
include Proxify::Me
|
5
|
+
|
6
|
+
proxy :hello, :say, :tell
|
7
|
+
|
8
|
+
def hello
|
9
|
+
"world"
|
10
|
+
end
|
11
|
+
|
12
|
+
def goodbye
|
13
|
+
"world"
|
14
|
+
end
|
15
|
+
|
16
|
+
def say(something)
|
17
|
+
something
|
18
|
+
end
|
19
|
+
|
20
|
+
def tell
|
21
|
+
yield
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
class AnotherProxied
|
27
|
+
include Proxify::Me
|
28
|
+
|
29
|
+
proxy :hello
|
30
|
+
|
31
|
+
def hello
|
32
|
+
"world"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe Proxied do
|
37
|
+
|
38
|
+
subject do
|
39
|
+
proxied = Proxied.new
|
40
|
+
proxied.proxy
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "Class Type" do
|
44
|
+
it "has the type of ProxiedProxy" do
|
45
|
+
subject.is_a?(ProxiedProxy).should == true
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe ".accept" do
|
50
|
+
it "accepts hello and rejects goodbye" do
|
51
|
+
subject.hello.should == "world"
|
52
|
+
expect { subject.goodbye }.to raise_error
|
53
|
+
end
|
54
|
+
|
55
|
+
it "can accept methods with arguments" do
|
56
|
+
subject.say("hello").should == "hello"
|
57
|
+
end
|
58
|
+
|
59
|
+
it "can accept a block" do
|
60
|
+
called = false
|
61
|
+
subject.tell do
|
62
|
+
called = true
|
63
|
+
end
|
64
|
+
called.should == true
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "a second proxied class" do
|
69
|
+
it "can handle more than one" do
|
70
|
+
another = AnotherProxied.new.proxy
|
71
|
+
subject.hello.should == another.hello
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
|
12
|
+
# Run specs in random order to surface order dependencies. If you find an
|
13
|
+
# order dependency and want to debug it, you can fix the order by providing
|
14
|
+
# the seed, which is printed after each run.
|
15
|
+
# --seed 1234
|
16
|
+
config.order = 'random'
|
17
|
+
|
18
|
+
require File.dirname(__FILE__) + '/../lib/proxify'
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: proxify
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Robbie Clutton
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-21 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Create a proxy for any object.
|
15
|
+
email:
|
16
|
+
- hello@iclutton.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- .rspec
|
23
|
+
- .travis.yml
|
24
|
+
- Gemfile
|
25
|
+
- LICENSE.txt
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- lib/proxify.rb
|
29
|
+
- lib/proxify/proxify.rb
|
30
|
+
- lib/proxify/version.rb
|
31
|
+
- proxify.gemspec
|
32
|
+
- spec/proxy_spec.rb
|
33
|
+
- spec/spec_helper.rb
|
34
|
+
homepage: ''
|
35
|
+
licenses: []
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options: []
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
hash: 3361068942138413123
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
hash: 3361068942138413123
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 1.8.24
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: Create a proxy for any object.
|
64
|
+
test_files:
|
65
|
+
- spec/proxy_spec.rb
|
66
|
+
- spec/spec_helper.rb
|