conject 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +14 -9
- data/README.md +13 -0
- data/lib/conject/object_factory.rb +8 -1
- data/lib/conject/version.rb +1 -1
- data/spec/acceptance/dev/is_spec.rb +33 -0
- data/spec/conject/object_factory_spec.rb +14 -0
- metadata +6 -4
data/CHANGELOG
CHANGED
@@ -1,7 +1,12 @@
|
|
1
|
+
Conject v0.1.2
|
2
|
+
* Aliasing objects via 'is', eg: context.configure_objects album: { is: "and_justice_for_all" }
|
3
|
+
Conject v0.1.1
|
4
|
+
* canonical private accessors for module-scoped object
|
5
|
+
|
1
6
|
Conject v0.1.0
|
2
7
|
* All objects now have a public accessor object_context
|
3
|
-
|
4
|
-
|
8
|
+
* provide_with_objects can be used like construct_with, except it sets up lazy use-time resolution of dependencies
|
9
|
+
* ObjectContext#put now raises if you accidentally re-register an object with the same name
|
5
10
|
|
6
11
|
Conject v0.0.9
|
7
12
|
* Classes with module namespaces can now refer to collaborators in construct_with by omitting the full path corresponding to the object namespace
|
@@ -16,17 +21,17 @@ Conject v0.0.6
|
|
16
21
|
|
17
22
|
Conject v0.0.5
|
18
23
|
* ObjectContext.configure_objects
|
19
|
-
|
20
|
-
|
24
|
+
* ... support :cache => false for objects, causing them to be non-singletons in context
|
25
|
+
* ... support :construct => lambda do |name, context| Something.new end
|
21
26
|
|
22
27
|
Conject v0.0.4
|
23
28
|
* Bug fixes / support for dealing with inheritance, ie, objects that inherit
|
24
|
-
|
29
|
+
from Conjected objects etc
|
25
30
|
|
26
31
|
Conject v0.0.3
|
27
|
-
|
28
|
-
|
32
|
+
* ObjectContext now caches self reference with key 'this_object_context'
|
33
|
+
allowing context injection into objects
|
29
34
|
|
30
35
|
Conject v0.0.1
|
31
|
-
|
32
|
-
|
36
|
+
* Automatic Type 1 object construction
|
37
|
+
* Nested ObjectContexts
|
data/README.md
CHANGED
@@ -90,4 +90,17 @@ subcontexts thereof. It also means that they will be preferred over any objects
|
|
90
90
|
All classes built within an ObjectContext are able to reference the context directly via the private accessor method "#object_context", which
|
91
91
|
is available as early as the call to #initialize.
|
92
92
|
|
93
|
+
# Aliasing #
|
94
|
+
The following will cause one object to be fulfilled by another. In this case, 'album' is not expected to be built
|
95
|
+
as an instance of the Album class, but rather will be set up as another name for 'and_justice_for_all':
|
96
|
+
|
97
|
+
context.configure_objects album: { is: 'and_justice_for_all' }
|
98
|
+
|
99
|
+
Both 'album' and 'and_justice_for_all' will be built in the context when 'album' is first requested.
|
100
|
+
This is more or less expressive shorthand for:
|
101
|
+
|
102
|
+
context['album'] = context['and_justice_for_all']
|
103
|
+
|
104
|
+
...EXCEPT that it's a lazy approach: using 'is' means nothing actually gets built or set in the context before it
|
105
|
+
is requested or composed into another object.
|
93
106
|
|
@@ -7,7 +7,14 @@ module Conject
|
|
7
7
|
object = nil
|
8
8
|
config = object_context.get_object_config(name)
|
9
9
|
lambda_constructor = config[:construct]
|
10
|
-
|
10
|
+
alias_for = config[:is]
|
11
|
+
if alias_for
|
12
|
+
begin
|
13
|
+
object = object_context.get(alias_for)
|
14
|
+
rescue Exception => ex
|
15
|
+
raise "(When attempting to fill alias '#{name}' with actual object '#{alias_for}') #{ex.message}"
|
16
|
+
end
|
17
|
+
elsif lambda_constructor
|
11
18
|
case lambda_constructor.arity
|
12
19
|
when 0
|
13
20
|
object = lambda_constructor[]
|
data/lib/conject/version.rb
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
|
2
|
+
|
3
|
+
describe "':is'" do
|
4
|
+
subject { new_object_context }
|
5
|
+
|
6
|
+
before do
|
7
|
+
append_test_load_path "basic_composition"
|
8
|
+
require 'ride_the_lightning'
|
9
|
+
require 'and_justice_for_all'
|
10
|
+
end
|
11
|
+
|
12
|
+
after do
|
13
|
+
restore_load_path
|
14
|
+
end
|
15
|
+
|
16
|
+
it "lets you alias one object for another" do
|
17
|
+
subject.configure_objects :album => { :is => :and_justice_for_all }
|
18
|
+
album = subject[:album]
|
19
|
+
|
20
|
+
album.should be
|
21
|
+
album.class.should == AndJusticeForAll
|
22
|
+
album.object_id.should == subject[:and_justice_for_all].object_id
|
23
|
+
end
|
24
|
+
|
25
|
+
it "provides good error message for missing target" do
|
26
|
+
subject.configure_objects :album => { :is => :mule_variations }
|
27
|
+
|
28
|
+
lambda do subject[:album] end.should raise_error(/when attempting to fill alias 'album'.*could not find.*MuleVariations/i)
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
end
|
33
|
+
|
@@ -113,6 +113,20 @@ describe Conject::ObjectFactory do
|
|
113
113
|
lambda do subject.construct_new(:the_two_many_params, object_context) end.should raise_error(/constructor lambda takes 0, 1 or 2 params/i)
|
114
114
|
end
|
115
115
|
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe "'is' aliasing" do
|
119
|
+
let(:object_config) do { :is => :specific_object } end
|
120
|
+
let(:specific_object) do "the specific object" end
|
121
|
+
|
122
|
+
before do
|
123
|
+
object_context.should_receive(:get_object_config).with(:generic_object).and_return(object_config)
|
124
|
+
object_context.should_receive(:get).with(:specific_object).and_return(specific_object)
|
125
|
+
end
|
126
|
+
|
127
|
+
it "specifies that the configured object should be 'built' by pulling its target object from the object context" do
|
128
|
+
subject.construct_new(:generic_object, object_context).should == specific_object
|
129
|
+
end
|
116
130
|
|
117
131
|
end
|
118
132
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: conject
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -117,6 +117,7 @@ files:
|
|
117
117
|
- scratch/sample.rb
|
118
118
|
- scratch/special_construct.rb
|
119
119
|
- spec/acceptance/dev/README
|
120
|
+
- spec/acceptance/dev/is_spec.rb
|
120
121
|
- spec/acceptance/dev/provide_with_objects_spec.rb
|
121
122
|
- spec/acceptance/regression/README
|
122
123
|
- spec/acceptance/regression/basic_composition_spec.rb
|
@@ -197,7 +198,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
197
198
|
version: '0'
|
198
199
|
segments:
|
199
200
|
- 0
|
200
|
-
hash:
|
201
|
+
hash: -606989410081679107
|
201
202
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
202
203
|
none: false
|
203
204
|
requirements:
|
@@ -206,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
206
207
|
version: '0'
|
207
208
|
segments:
|
208
209
|
- 0
|
209
|
-
hash:
|
210
|
+
hash: -606989410081679107
|
210
211
|
requirements: []
|
211
212
|
rubyforge_project:
|
212
213
|
rubygems_version: 1.8.24
|
@@ -215,6 +216,7 @@ specification_version: 3
|
|
215
216
|
summary: Enable Guice-like dependency injection and contextual object interactions.
|
216
217
|
test_files:
|
217
218
|
- spec/acceptance/dev/README
|
219
|
+
- spec/acceptance/dev/is_spec.rb
|
218
220
|
- spec/acceptance/dev/provide_with_objects_spec.rb
|
219
221
|
- spec/acceptance/regression/README
|
220
222
|
- spec/acceptance/regression/basic_composition_spec.rb
|