proxify 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.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
@@ -0,0 +1,3 @@
1
+ rvm:
2
+ - 1.9.2
3
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in proxy.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'rspec'
8
+ gem 'rake'
9
+ gem 'guard-rspec'
10
+ end
@@ -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.
@@ -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
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ task :rspec do
5
+ if system("bundle exec rspec spec")
6
+ puts "Specs passed!"
7
+ else
8
+ puts "Specs failed!!!"
9
+ exit(1)
10
+ end
11
+ end
12
+
13
+ task :default => [:rspec]
@@ -0,0 +1,3 @@
1
+ require "proxify/version"
2
+ require "proxify/proxify"
3
+
@@ -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
@@ -0,0 +1,3 @@
1
+ module Proxify
2
+ VERSION = "0.0.1"
3
+ end
@@ -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
@@ -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
@@ -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