proxy_party 0.1.0

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.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Kristian Mandrup
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,67 @@
1
+ # Proxy Party
2
+
3
+ Greatly facilitates adding proxies through the proxy method_missing pattern
4
+
5
+ ## Install ##
6
+
7
+ <code>$ gem install party_proxy</code>
8
+
9
+ ## Usage Configuration ##
10
+
11
+ <code>require 'party_proxy'</code>
12
+
13
+ ## Usage ##
14
+
15
+ <pre><code>
16
+ class State
17
+ attr_accessor :name
18
+
19
+ def initialize(name)
20
+ @name = name
21
+ end
22
+ end
23
+
24
+ class Info
25
+ attr_accessor :text
26
+
27
+ def initialize(text)
28
+ @text = text
29
+ end
30
+ end
31
+
32
+ module Party
33
+ class Subject
34
+ # proxy state and info objects to make their methods
35
+ # directly accessible from subject objects
36
+ proxy :state, :info
37
+
38
+ def initialize(name)
39
+ @state = State.new name
40
+ @info = Info.new 'hello'
41
+ end
42
+ end
43
+ end
44
+
45
+ subject = Party::Subject.new 'kristian'
46
+ # access 'name' directly through 'state' proxy
47
+ puts subject.name
48
+ # access 'text' directly through 'info' proxy
49
+ puts subject.text
50
+
51
+ => 'kristian'
52
+ => 'hello'
53
+ </code></pre>
54
+
55
+ ## Note on Patches/Pull Requests ##
56
+
57
+ * Fork the project.
58
+ * Make your feature addition or bug fix.
59
+ * Add tests for it. This is important so I don't break it in a
60
+ future version unintentionally.
61
+ * Commit, do not mess with rakefile, version, or history.
62
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
63
+ * Send me a pull request. Bonus points for topic branches.
64
+
65
+ ## Copyright ##
66
+
67
+ Copyright (c) 2010 Kristian Mandrup. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "proxy_party"
8
+ gem.summary = %Q{Add proxy functionality the fun way}
9
+ gem.description = %Q{Method missing proxy pattern}
10
+ gem.email = "kmandrup@gmail.com"
11
+ gem.homepage = "http://github.com/kristianmandrup/proxy_party"
12
+ gem.authors = ["Kristian Mandrup"]
13
+ # gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ # require 'spec/rake/spectask'
22
+ # Spec::Rake::SpecTask.new(:spec) do |spec|
23
+ # spec.libs << 'lib' << 'spec'
24
+ # spec.spec_files = FileList['spec/**/*_spec.rb']
25
+ # end
26
+ #
27
+ # Spec::Rake::SpecTask.new(:rcov) do |spec|
28
+ # spec.libs << 'lib' << 'spec'
29
+ # spec.pattern = 'spec/**/*_spec.rb'
30
+ # spec.rcov = true
31
+ # end
32
+ #
33
+ # task :spec => :check_dependencies
34
+ #
35
+ # task :default => :spec
36
+ #
37
+ # require 'rake/rdoctask'
38
+ # Rake::RDocTask.new do |rdoc|
39
+ # version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+ #
41
+ # rdoc.rdoc_dir = 'rdoc'
42
+ # rdoc.title = "proxy_party #{version}"
43
+ # rdoc.rdoc_files.include('README*')
44
+ # rdoc.rdoc_files.include('lib/**/*.rb')
45
+ # end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,34 @@
1
+ module Party
2
+ module Proxy
3
+
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ end
7
+
8
+ # Define class methods here.
9
+ module ClassMethods
10
+ attr_accessor :proxies
11
+ end
12
+
13
+ # proxy to state
14
+ def method_missing(name, *args, &block)
15
+ self.class.proxies.each do |proxi|
16
+ proxy_obj = self.send proxi
17
+ return proxy_obj.send name, *args, &block if proxy_obj.respond_to? :"#{name}"
18
+ end
19
+ super
20
+ end
21
+ end
22
+ end
23
+
24
+ class Class
25
+ def proxy *proxy_objs
26
+ include Party::Proxy
27
+
28
+ proxy_objs.each do |proxy_obj|
29
+ attr_accessor proxy_obj
30
+ @proxies ||= []
31
+ @proxies << proxy_obj
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,37 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ class State
4
+ attr_accessor :name
5
+
6
+ def initialize(name)
7
+ @name = name
8
+ end
9
+ end
10
+
11
+ class Info
12
+ attr_accessor :text
13
+
14
+ def initialize(text)
15
+ @text = text
16
+ end
17
+ end
18
+
19
+
20
+ module Party
21
+ class Subject
22
+ proxy :state, :info
23
+
24
+ def initialize(name)
25
+ @state = State.new name
26
+ @info = Info.new 'hello'
27
+ end
28
+ end
29
+ end
30
+
31
+ describe Party::Proxy do
32
+ it "proxies state so it can call name directly on subject" do
33
+ subject = Party::Subject.new 'kristian'
34
+ subject.name.should == 'kristian'
35
+ subject.text.should == 'hello'
36
+ end
37
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,3 @@
1
+ require 'rspec'
2
+ require 'rspec/autorun'
3
+ require 'proxy_party'
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: proxy_party
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Kristian Mandrup
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-06-18 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Method missing proxy pattern
22
+ email: kmandrup@gmail.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - LICENSE
29
+ - README.markdown
30
+ files:
31
+ - .document
32
+ - .gitignore
33
+ - LICENSE
34
+ - README.markdown
35
+ - Rakefile
36
+ - VERSION
37
+ - lib/proxy_party.rb
38
+ - spec/proxy_party_spec.rb
39
+ - spec/spec.opts
40
+ - spec/spec_helper.rb
41
+ has_rdoc: true
42
+ homepage: http://github.com/kristianmandrup/proxy_party
43
+ licenses: []
44
+
45
+ post_install_message:
46
+ rdoc_options:
47
+ - --charset=UTF-8
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ requirements: []
67
+
68
+ rubyforge_project:
69
+ rubygems_version: 1.3.7
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Add proxy functionality the fun way
73
+ test_files:
74
+ - spec/proxy_party_spec.rb
75
+ - spec/spec_helper.rb