group_delegator 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/group_delegator.gemspec +83 -0
- data/lib/group_delegator/group_delegator_klasses.rb +13 -2
- data/spec/group_delegator_klasses_spec.rb +25 -1
- metadata +5 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{group_delegator}
|
8
|
+
s.version = "0.1.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Dave M"]
|
12
|
+
s.date = %q{2011-03-17}
|
13
|
+
s.description = %q{A wrapper that allows method calls to multiple objects with various concurrency models}
|
14
|
+
s.email = %q{dmarti21@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"LICENSE.txt",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"examples/compare_to_map.rb",
|
27
|
+
"examples/diff_w_map.rb",
|
28
|
+
"examples/find_troublemakers.rb",
|
29
|
+
"examples/remote_component_update_sim.rb",
|
30
|
+
"examples/search_examples_with_benchmarks.rb",
|
31
|
+
"group_delegator.gemspec",
|
32
|
+
"lib/group_delegator.rb",
|
33
|
+
"lib/group_delegator/group_delegator_instances.rb",
|
34
|
+
"lib/group_delegator/group_delegator_klasses.rb",
|
35
|
+
"lib/group_delegator/source_group.rb",
|
36
|
+
"lib/group_delegator/source_helper.rb",
|
37
|
+
"spec/group_delegator_instances_spec.rb",
|
38
|
+
"spec/group_delegator_klasses_spec.rb",
|
39
|
+
"spec/group_delegator_spec.rb",
|
40
|
+
"spec/source_group_spec.rb",
|
41
|
+
"spec/spec_helper.rb"
|
42
|
+
]
|
43
|
+
s.homepage = %q{http://github.com/forforf/group_delegator}
|
44
|
+
s.licenses = ["MIT"]
|
45
|
+
s.require_paths = ["lib"]
|
46
|
+
s.rubygems_version = %q{1.3.7}
|
47
|
+
s.summary = %q{Delegate to multiple objects concurrently}
|
48
|
+
s.test_files = [
|
49
|
+
"examples/compare_to_map.rb",
|
50
|
+
"examples/diff_w_map.rb",
|
51
|
+
"examples/find_troublemakers.rb",
|
52
|
+
"examples/remote_component_update_sim.rb",
|
53
|
+
"examples/search_examples_with_benchmarks.rb",
|
54
|
+
"spec/group_delegator_instances_spec.rb",
|
55
|
+
"spec/group_delegator_klasses_spec.rb",
|
56
|
+
"spec/group_delegator_spec.rb",
|
57
|
+
"spec/source_group_spec.rb",
|
58
|
+
"spec/spec_helper.rb"
|
59
|
+
]
|
60
|
+
|
61
|
+
if s.respond_to? :specification_version then
|
62
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
63
|
+
s.specification_version = 3
|
64
|
+
|
65
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
66
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
67
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
68
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
69
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
70
|
+
else
|
71
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
72
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
73
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
74
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
75
|
+
end
|
76
|
+
else
|
77
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
78
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
79
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
80
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
@@ -27,7 +27,7 @@ class GroupDelegatorKlasses
|
|
27
27
|
def __source_classes
|
28
28
|
@sources
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
end #class<<self
|
32
32
|
|
33
33
|
#initializing class instance variables
|
@@ -40,12 +40,23 @@ class GroupDelegatorKlasses
|
|
40
40
|
raise NoMethodError, "#{self.class} can't find the class method #{m} in any of its sources"
|
41
41
|
end
|
42
42
|
end
|
43
|
+
|
44
|
+
attr_reader :__objs_by_class
|
43
45
|
|
44
46
|
def initialize(*args)
|
45
47
|
#changed self to self.class
|
46
48
|
concurrency_model = self.class.__concurrency_model
|
47
49
|
raise "No Source Classes set" unless self.class.__source_classes.size > 0
|
48
|
-
|
50
|
+
@__objs_by_class = {}
|
51
|
+
proxied_objs = []
|
52
|
+
self.class.__source_classes.each do |klass|
|
53
|
+
@__objs_by_class[klass] ||= []
|
54
|
+
proxied_obj = klass.new(*args)
|
55
|
+
@__objs_by_class[klass] << proxied_obj
|
56
|
+
end
|
57
|
+
proxied_objs = @__objs_by_class.values.flatten
|
58
|
+
#p proxied_objs
|
59
|
+
#proxied_objs = self.class.__source_classes.map {|klass| klass.new(*args) }
|
49
60
|
sources_data = SourceHelper.set_sources_data(proxied_objs)
|
50
61
|
@source_obj_methods = sources_data[:source_methods]
|
51
62
|
@source_objects = sources_data[:source_objs]
|
@@ -82,15 +82,39 @@ shared_examples_for "instance delegator - entire collection" do
|
|
82
82
|
it "passes methods to the underlying instances of the group" do
|
83
83
|
group_obj.common_method.values == [:a, :b, :c]
|
84
84
|
end
|
85
|
+
|
86
|
+
#tests __objs_by_class method
|
87
|
+
it "can access the instances via their class names" do
|
88
|
+
objs = group_obj.common_method.keys
|
89
|
+
objs.each do |obj|
|
90
|
+
obj_class = obj.class
|
91
|
+
this_objs = group_obj.__objs_by_class[obj_class]
|
92
|
+
raise "Unexpected size of #{this_objs.size} != 1" unless this_objs.size == 1
|
93
|
+
this_obj = this_objs.first if this_objs.size == 1
|
94
|
+
this_obj.should == obj
|
95
|
+
end
|
96
|
+
end
|
85
97
|
end
|
86
98
|
|
87
99
|
shared_examples_for "instance delegator - first response" do
|
88
|
-
it "passes methods to the first
|
100
|
+
it "passes methods to the first responding instance" do
|
89
101
|
expected_result_set = [:a, :b, :c]
|
90
102
|
result = group_obj.common_method
|
91
103
|
result_value = result.values.first
|
92
104
|
expected_result_set.should include result_value
|
93
105
|
end
|
106
|
+
#tests __objs_by_class method
|
107
|
+
it "can access the instances via their class names" do
|
108
|
+
objs = group_obj.common_method.keys #its only one object though
|
109
|
+
objs.size.should == 1
|
110
|
+
objs.each do |obj|
|
111
|
+
obj_class = obj.class
|
112
|
+
this_objs = group_obj.__objs_by_class[obj_class]
|
113
|
+
raise "Unexpected size of #{this_objs.size} != 1" unless this_objs.size == 1
|
114
|
+
this_obj = this_objs.first if this_objs.size == 1
|
115
|
+
this_obj.should == obj
|
116
|
+
end
|
117
|
+
end
|
94
118
|
end
|
95
119
|
|
96
120
|
describe "delegating to a group of classes" do
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 2
|
9
|
+
version: 0.1.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Dave M
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-03-
|
17
|
+
date: 2011-03-17 00:00:00 +00:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -96,6 +96,7 @@ files:
|
|
96
96
|
- examples/find_troublemakers.rb
|
97
97
|
- examples/remote_component_update_sim.rb
|
98
98
|
- examples/search_examples_with_benchmarks.rb
|
99
|
+
- group_delegator.gemspec
|
99
100
|
- lib/group_delegator.rb
|
100
101
|
- lib/group_delegator/group_delegator_instances.rb
|
101
102
|
- lib/group_delegator/group_delegator_klasses.rb
|
@@ -120,7 +121,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
120
121
|
requirements:
|
121
122
|
- - ">="
|
122
123
|
- !ruby/object:Gem::Version
|
123
|
-
hash:
|
124
|
+
hash: -932509869
|
124
125
|
segments:
|
125
126
|
- 0
|
126
127
|
version: "0"
|